Which of the following declares ‘pf’ as a pointer to a function, which returns…
2017
Which of the following declares ‘pf’ as a pointer to a function, which returns an integer quantity and requires two integer arguments?
- A.
int *pf(int, int);
- B.
int (*pf) (int, int);
- C.
(int *) pf(int, int);
- D.
int (int *pf(int, int));
Attempted by 337 students.
Show answer & explanation
Correct answer: B
In C, parentheses surrounding the pointer operator and identifier (*pf) are required to override standard operator precedence. Without them, the function call operator () binds tighter than the pointer operator *. Therefore, int (*pf)(int, int); successfully declares pf as a pointer to a function returning an integer and accepting two integer arguments.
Thus, the correct option is B.