Dynamically Allocating 2-D Arrays: Spring Semester 2011 Programming and Data Structure 1
Dynamically Allocating 2-D Arrays: Spring Semester 2011 Programming and Data Structure 1
sizeof(int): 4
sizeof(int *): 4
sizeof(int [5]): 20
sizeof(int (*)[5]): 4
sizeof(int **): 4
int (*q)[5];
q
Dynamically allocated memory
return 0;
}
int *r[3], i;
for (i=0;i<3;i++)
r[i] = (int *) malloc (m*sizeof(int));
r[1]
r[2]
int **s;
s = (int **) malloc (r*sizeof(int *));
for (i=0;i<r;i++)
s[i] = (int *) malloc (c*sizeof(int));
s[0]
s[1]
s[2]
:
Dynamically allocated memory
Elements accessed
like 2-D array elements.