Home:ALL Converter>Pointer to array and dynamic memory allocation

Pointer to array and dynamic memory allocation

Ask Time:2015-04-14T18:16:46         Author:user231243

Json Formatter

How can one create 2-D array using pointer to array in C and dynamic memory allocation, without using typedef and without using malloc at time of pointer to array declaration? How do we typecast for pointer to array? In general how can we create a[r][c] , starting from int (*a)[c] and then allocate memory for "r" rows ?

For ex. If we need to create a[3][4] , Is this how we do ?

int (*a)[4];

a= (int (*) [4]) malloc (3*sizeof (int *));

Author:user231243,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29624765/pointer-to-array-and-dynamic-memory-allocation
yy