Question 11
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int add(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
int main(void) {
int (*op)(int, int) = add;
printf("%d ", op(3, 4));
op = mul;
printf("%d\n", op(3, 4));
return 0;
}
- A 7 7
- B 12 12
- C 7 12 Correct
- D Compilation error
Correct Answer: Option C
op first points to add, so op(3, 4) is 7. After op = mul, the same call runs mul and gives 12.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!