Well, if you want to allocate array of type, you assign it into a pointer of that type.
Since 2D arrays are arrays of arrays (in your case, an array of 512 arrays of 256 chars), you should assign it into a pointer to array of 256 chars:
char (*arr)[256]=malloc(512*256);
//Now, you can, for example:
arr[500][200]=75;
(The parentheses around *arr
are to make it a pointer to array, and not an array of pointers)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…