Pointers and Arrays??
How are these three different from each other:
int a[3][4];
int* a[4];
int (*a)[4];
?
My goal is to create a 3x4 2D array. I can understand the first and second statements. But the third I have no idea.
Thanks in advance.
The third declares a pointer to an array of 4 elements.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <stdio.h>
int foo () { return 99; };
int main()
{
int x[4] = { 11, 22, 33, 44 };
int (*y)[4] = { &x }, i;
for (i = 0; i < 4; ++i)
printf("%d %d\n", (*y)[i], x[i]);
return 0;
}
|
Topic archived. No new replies allowed.