← Quiz: Function Pointers in C: all 15 questions
Quiz: Function Pointers in C · Question 11 of 15
What does this print? (code)
What does this print?
#include <stdio.h>
int add(int a, int b) { return a + b; }
int sub(int a, int b) { return a - b; }
int mul(int a, int b) { return a * b; }
int main(void) {
int (*ops[3])(int, int) = {add, sub, mul};
printf("%d %d %d\n", ops[0](6, 2), ops[1](6, 2), ops[2](6, 2));
return 0;
}
- A.8 8 8
- B.8 4 12
- C.12 4 8
- D.Compile error
Answer & explanation
Correct answer: 8 4 12
ops is an array of three function pointers, and each call runs the function stored at that index.
Can you get the rest right without peeking?
Take the timed Quiz: Function Pointers in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →