# Thread: pointer to int array?

1. ## pointer to int array?

Hi, I have been battling with this one for too long, so I'll just ask you guys here, lets start slow.

Code:
```typedef int (*ImagePointer)[3];  // is this same as if I say
ImagePointer my_point;  // int (*my_point)[3]; (pretty sure it is)```
Now moving on

Code:
```typedef int (*ImagePointer)[3];

ImagePointer my_point;
int a[3];

my_point = &a; // this is where it starts confusing me, the problem is that I don't even //understand what exactly is a pointer to an int array```
So basically what I am asking for is a quick explanation what exactly is this pointer, because it is not an array of pointers (i.e. int *p[3], this would give me 3 pointers), or just an example, examples can teach a lot .

Thanks

2. I think this is a pointer to a 2d array of integers (3x3).

without the brackets it would be 3 pointers.

3. It's just one pointer, but it points at 3 ints (in an array).

Code:
```int a[3];
int *pa = &a[0];  // an integer
int (*pa)[3] = &a;  // an array of 3 ints```
You need the parentheses so you get "pointer (singular) to an array (of 3 ints)".
Without them, int *pa[3] is "array of (three) pointers (plural) to int".

Also, you can do this
Code:
```int a[3];
int b[7][3];
int (*pa)[3];
pa = &a;
pa = b[0];
pa = &b[0][0];```
You see the same syntax when you pass a 2D array as a parameter to a function.

Consider this alternative example
Code:
```struct foo {
int a;
int b;
int c;
} bar;
int *pa = &bar.a;  // pointer to one int
struct foo *pa = &bar;  // pointer to the whole thing```
In both cases, one is a pointer to the first element of the compound object (array or struct), and the second is a pointer to the whole thing.

4. Thank you very much Salem, this is what I call an explanation

Popular pages Recent additions