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?

  1. A.

    int *pf(int, int);

  2. B.

    int (*pf) (int, int);

  3. C.

    (int *) pf(int, int);

  4. 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.

Explore the full course: Coal India Management Trainee