Hi guys...
consider this...
int a[10][3];
will give us a two dimensional array.
Now can we do the same thing using malloc at run
time?? Think.... :D
Hi guys...
consider this...
int a[10][3];
will give us a two dimensional array.
Now can we do the same thing using malloc at run
time?? Think.... :D
In C:
int **a, x;
a = malloc(sizeof(int *) * 10);
for(x = 0; x < 10; x ++) {
a[x] = malloc(sizeof(int) * 3);
}
/* ... */
for(x = 0; x < 10; x ++) {
free(a[x]);
}
free(a);
You can even enlarge the array, or shrink it or whatever, using realloc().
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.