Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;指向数组的指针的指针_C++_Arrays_Pointers_G++_Core - Fatal编程技术网

C++ C++;指向数组的指针的指针

C++ C++;指向数组的指针的指针,c++,arrays,pointers,g++,core,C++,Arrays,Pointers,G++,Core,我在创建数组数组或指向数组的指针数组方面有点问题。更准确地说,我似乎已经消除了所有错误,因为程序编译得很好(我使用的是g++),但是当我尝试运行它时,它会给出一个“内核转储”消息 这是我的密码 #include<iostream> #include<ctime> #include<cstdlib> using namespace std; void create_array(int **pp) { pp = new int*[4];

我在创建数组数组或指向数组的指针数组方面有点问题。更准确地说,我似乎已经消除了所有错误,因为程序编译得很好(我使用的是g++),但是当我尝试运行它时,它会给出一个“内核转储”消息

这是我的密码

#include<iostream>
#include<ctime>
#include<cstdlib>

using namespace std;

void create_array(int **pp)
    {
        pp = new int*[4];
        for (int i = 0; i<4; i++)
        {
            pp[i] = new int[4];
        }
    }

int main()
    {
        srand(time(NULL));
        int **pp;
        create_array(pp);

        for (int x = 0; x<4; x++)
        {
            for(int y = 0; y<4; y++)
            {
                pp[x][y] = rand()%9;
            }
        }
        cout << pp[3][2] << endl;
        return 0;
    }
#包括
#包括
#包括
使用名称空间std;
无效创建数组(整数**pp)
{
pp=新整数*[4];
对于(int i=0;i
通过上述更改,如果您尝试在我的机器上打印整个矩阵,它将输出以下内容:

 8 7 6 3
 3 5 6 4
 3 8 7 6
 0 0 5 8

您不想初始化指针,做一个引用。< /p>编译所有警告和调试信息>代码> g++-墙壁-g/c>,学会使用<代码> gdB < /C>调试程序,并考虑使用C++容器(如<代码> STD::vector < /COD>);您的<代码> pp<代码>是一个统一指针。(<代码> > CuraTyRealEngs<代码>创建的内存区域目前无法从<代码>主< /代码>中考虑;考虑从“代码> CREATEY数组> <代码>返回指针。
void create_array(int **&pp)
{                     //^^
    pp = new int*[4];
    for (int i = 0; i<4; i++)
    {
        pp[i] = new int[4];
    }
}
 8 7 6 3
 3 5 6 4
 3 8 7 6
 0 0 5 8