Assign Memory to 3D array using triple pointer

后端 未结 5 826
别跟我提以往
别跟我提以往 2021-01-01 05:54

I have to assign memory to a 3D array using a triple pointer.

#include 
int main()
{
    int m=10,n=20,p=30;
    char ***z;
    z = (char***)          


        
5条回答
  •  一生所求
    2021-01-01 06:23

    You would need the following nested loop -

    z = (char**)malloc(sizeof(char*) * m);
    for (int i = 0; i < m; ++i)
    {
        *(z + i) = (char*)malloc(sizeof(char*) * n);
        for (int j = 0; j < n; ++j)
        {
            *(*(z + i)) = (char)malloc(p);
        }
    }
    

    May not be synactically accurate, but it should be something along these lines.

提交回复
热议问题