The following statement in ‘C’ int (*f())[ ]; declares
2016
The following statement in ‘C’
int (*f())[ ];
declares
- A.
a function returning a pointer to an array of integers.
- B.
a function returning an array of pointers to integers.
- C.
array of functions returning pointers to integers.
- D.
an illegal statement.
Attempted by 220 students.
Show answer & explanation
Correct answer: A
Answer: This declares a function returning a pointer to an array of integers.
Explanation (read inside-out):
f() : f is a function (parentheses after the name indicate a function).
(*f()) : the parentheses put * with the function result, so the function returns a pointer.
(*f())[ ] : the pointer points to an array; the base type given is int, so it is a pointer to an array of int.
Putting it together: f is a function returning a pointer to an array of integers.
Note: Functions cannot return arrays directly, which is why the declaration returns a pointer to an array rather than an array value. The empty brackets indicate an array type with unspecified size (an incomplete array type) in the declaration context.