我有一个char***,我动态地为它分配了一些内存.但是,当我尝试为其分配一些值时,我会遇到分段错误.我使用的尺寸不是太大.它在我创建char [768] [1024] [3]时有效但在我用相同的精确值动态添加它时不起作用.这是我的代码片段:
pic = new char**[height];
for(int i = 0; i < height; i++)
{
pic[i] == new char*[width];
for(int j = 0; j< width; j++)
{
pic[i][j] == new char[3];
}
}
pic[0][0][0] = 'a';//seg fault here
exit(1);
Run Code Online (Sandbox Code Playgroud) c++ segmentation-fault multidimensional-array dynamic-memory-allocation