When creating a pointer array in c what does the effect of adding parentheses do?
For example
int (*poi)[2];
vs
int *poi[2];
Pointer to an array of 2 ints:
int (*poi)[2];
An array of two int pointers:
int *poi[2];
Normally Array has higher precedence than the pointer, but if you add the parentheses then the pointer comes "first".
The index operator [] binds stronger than the derefentiation operator *.
int *poi[2]
translates to:
If you see poi, apply [x] to it, then dereference the result via * and you get an int.
So it's an array of 2 pointers to int.
In
int (*poi)[2]
the parantheses force the * to be applied first.
So anytime poi is used, if you apply * first, and then [x] you get an int.
So it's a pointer to an array of 2 int.
Brackets bind tighter than *, so the first is an array of int pointers, while the second is a pointer to an array of ints.