GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 1

Reading a function-pointer declaration

Programming in C · Structures & Declarations · Full GATE CSE 2005 paper

GATE 2005, Q1 1 mark · MCQ
Report issue

Structures & Declarations

Question 1, GATE 2005: Interpret C declaration int (*f)(int *). A function taking int* and returning int; B function taking int and returning int*; C pointer to function taking int* and returning int; D function taking int* and returning a function pointer.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

In int (*f)(int *), the parentheses make f a pointer. Its target is a function taking one int-pointer argument and returning int. Thus C; it is not a function returning a pointer.

Read outward from f. The parentheses bind *f before the following parameter list, so f is a pointer. Its pointed-to object is a function whose parameter is int* and whose return type, written at the left, is int. Without parentheses, int *f(int*) would instead declare a function returning int*. That binding distinction gives C.

Original paper, page 1