V
Vijay Kumar R Zanvar
Hi c.l.c,
Is this a correct method of allocating a 3-dimensional
array?
/* assume all malloc's succeed */
#define MAT 2
#define ROW 2
#define COL 2
char ***ptr = malloc ( MAT * sizeof *ptr );
for ( i = 0; i < MAT; i++ )
ptr = malloc ( ROW * sizeof **ptr );
for ( i = 0; i < MAT; i++ )
for ( j = 0; j < ROW; j++ )
ptr[j] = malloc ( COL * sizeof ***ptr );
Thanks.
Is this a correct method of allocating a 3-dimensional
array?
/* assume all malloc's succeed */
#define MAT 2
#define ROW 2
#define COL 2
char ***ptr = malloc ( MAT * sizeof *ptr );
for ( i = 0; i < MAT; i++ )
ptr = malloc ( ROW * sizeof **ptr );
for ( i = 0; i < MAT; i++ )
for ( j = 0; j < ROW; j++ )
ptr[j] = malloc ( COL * sizeof ***ptr );
Thanks.