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.

Comments

Popular posts from this blog

ZoneAlarm Extreme Security

4 Brains in 1

Billing and CRM Systems