Array of Pointers & Pointer to an entire array

Lets take it by an example:

int *p[N]; , where N is any integer number is a declaration for an array of N pointers of type int. This means that if we declare as:
int *p[5]; then, p[0], p[1]. … ,p[4] will all be pointers of type int, ie,, they point to memory locations allocated for integer data.

Coming to Pointer to an entire array can be declared as say:

int (*a)[N]; where N is any integer number.

This means that int (*a)[5]; is the declaration for a pointer to an array of length 5 of type int.

This is purely a matter of precedence. In the former case, for int *p[5]; Since [] has higher precedence that *, p is recognized as an array first and the * shows that it an array of integer pointers.
For the secod case, for int(*a)[5]; the default precedence is overridden by the common paranthesis. Thus, now a is a pointer first and the [] makes it a pointer to an array.

More From Author

The closest thing to replace pen and paper for good :)

I have used two other styluses namely, the Bamboo Stylus and the Cregle iPen. By…

Apple Event October 2012

Been watching the live streaming of the Oct 23rd apple event. This is the event where…

Bootcamping Windows 8

Finally installed Windows 8 to Bootcamp(to non-mac users, this means that the windows now runs…

Leave a Reply

Your email address will not be published. Required fields are marked *