开发者

Run-time/Compile-time initialization of char***

How do I initiali开发者_高级运维ze char*** p at run-time or compile-time?


Initialize with a null pointer

char*** p = 0; //or NULL, or nullptr

Another option

char x;
char *y = &x;
char **z = &y;
char ***p = &z;

Allocating memory?

char *** p = new char**[dim1];
for(int i = 0; i < dim1; ++i)
{
   p[i] = new char*[dim2];
   for(int j = 0; j < dim2; ++j)
   {
       p[i][j] = new char[dim3];
   }
}


Well, here's one example:

char A = 'A';
char *pA = &A;
char **ppA = &pA;
char ***p = &ppA;   // Now `***p` will dereference all the way back to 'A'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜