What does the following C-statement declare?
int (*f) (int * );
View worked solution
Answer: C
We can decode the C declaration int (*f) (int *); using the operator precedence rules (or the spiral rule) for C declarations:
-
Identify the identifier: Start with the variable name, which is
f. -
Check parentheses: Inside the parentheses, we have
*f. The asterisk (*) indicates thatfis a pointer. -
Look to the right: Outside the parentheses on the right, we see
(int *). This indicates thatfpoints to a function taking anint *(pointer to an integer) as its argument. -
Look to the left: On the far left, we have the return type
int. This means the function returns an integer.
Combining these steps, f is a pointer to a function that takes an integer pointer as an argument and returns an integer.
Therefore, the correct option is C.
Free practice · Your answers on this page are not saved.
