Difficulty: Medium
Correct Answer: f is a function returning pointer to an int.
Explanation:
Introduction / Context:
Distinguishing “function returning pointer” from “pointer to function” is a frequent stumbling block in C. The position of parentheses relative to * and the identifier determines whether you declare a function or a pointer to a function. This question focuses on the declaration int *f();
Given Data / Assumptions:
Concept / Approach:
Operator precedence puts () on the identifier first. Because there are no parentheses around *f, the () applies to f, making f a function. The return type is int*, derived from the leading int *. Therefore, f is a function that, when called, returns a pointer to int. By contrast, a pointer to function returning int would look like int (*pf)();
Step-by-Step Solution:
Verification / Alternative check:
Introduce a typedef for clarity: typedef int* pint; then pint f(); reads more naturally as “f returns pint”, confirming the interpretation. Another check is to compare with int (*f)(); which would be a pointer to a function returning int, clearly different.
Why Other Options Are Wrong:
Pointer variable of function type: Functions are not objects; you cannot have “pointer variable of function type” as phrased. The declaration does not make f a pointer variable at all.
Function pointer: That would require parentheses around *f: int (*f)();
Simple declaration of pointer variable: A simple pointer variable would be int *p; with no ().
Common Pitfalls:
Final Answer:
f is a function returning pointer to an int.
Discussion & Comments