开发者

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

开发者 https://www.devze.com 2023-03-24 21:20 出处:网络
How do I initiali开发者_高级运维ze char*** p at run-time or compile-time?Initialize with a null pointer

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

精彩评论

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