ProgrammingModerateHCL · Tech Mahindra pattern

What is printed?

What is printed?
int add(int a, int b) { return a + b; }
...
int (*fp)(int, int) = add;
printf("%d", (*fp)(2, 3) + fp(4, 5));
  1. A. Compilation error
  2. B. 9
  3. C. 14
  4. D. 5

Correct answer: C. 14

fp points to add. A function pointer can be called either as (*fp)(...) or directly as fp(...); both are valid C. So 5 + 9 = 14.

More C Programming questions

Exams that ask this topic