1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Which declaration creates a pointer to a function taking…

Added 30 Nov -0001

Which declaration creates a pointer to a function taking two ints and returning an int?

  1. int *(fp(int, int));
  2. int fp(*)(int, int);
  3. int (*fp)(int, int); Correct answer
  4. int *fp(int, int);

Correct answer

C. int (*fp)(int, int);

20 views

MCQSEXAM

Explanation

The parentheses around (*fp) bind the star to the name before the call parentheses apply, so fp is a pointer to a function, not a function returning a pointer. Without them, int *fp(int, int) declares a function returning int*. Function pointers enable callbacks such as qsort's comparator and are dereferenced implicitly when called, so fp(1, 2) and (*fp)(1, 2) are equivalent.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs