What is the meaning of the following declaration in C programming language?…
2018
What is the meaning of the following declaration in C programming language?
int (*p)[5];
- A.
It will result in compile error because there should not be any parenthesis, i.e., "int *p[5]" is valid
- B.
p is a pointer to 5 integers
- C.
p is a pointer to integer array
- D.
p is a pointer to an array of 5 integers
Attempted by 128 students.
Show answer & explanation
Correct answer: D
The Parentheses Matter: In C, the array subscript operator
[]has higher precedence than the pointer operator*. By enclosing*pin parentheses(*p), we force the compiler to bind the pointer operator topfirst.Decoding
int (*p);:Look inside the parentheses:
(*p)meanspis a pointer.Look outside to the right: `` means it points to an array of 5 elements.
Look to the far left:
intmeans those elements are of integer data type.
Putting it all together: p is a pointer to an array of 5 integers.