EDIT
I've read the question and answers here: C pointer to array/array of pointers disambiguation. The answers there do not address the focus of my questions here as well as some of the answers already posted below. This is similar, but not a duplicate. The focus here is intended to be centered around explaining how the ()
changes the declaration. The focus in the link is broader, and in fact does not center around the impact and effect of ()
on a declaration such as the ones I include below.
What is the reason for the difference in the way
int *a[5];
int (*a)[5];
are created?
I am particularly interested in an explanation of how the ()
changes the declaration.
For example:
With 1)
a[0] = malloc(sizeof(int)); //compiles
But with 2) it does not. ( error: array type int [5] is not assignable )
Questions:
1) What is the effect of the ()
in 2)
?
2) Why would declaration 2
ever be used over declaration 1?
(that is, why would declaration 2
ever be used?)