← Quiz: Function Pointers in C: all 15 questions
Quiz: Function Pointers in C · Question 12 of 15
What does this print? (code)
What does this print?
#include <stdio.h>
int twice(int x) { return 2 * x; }
int sq(int x) { return x * x; }
int apply(int (*f)(int), int v) { return f(f(v)); }
int main(void) {
printf("%d %d\n", apply(twice, 3), apply(sq, 3));
return 0;
}
- A.6 9
- B.12 18
- C.12 81
- D.9 81
Answer & explanation
Correct answer: 12 81
apply calls the function twice: twice(twice(3)) = 12 and sq(sq(3)) = sq(9) = 81.
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 →