← Quiz: Function Pointers in C: all 15 questions
Quiz: Function Pointers in C · Question 2 of 15
What does this print? (code)
What does this print?
#include <stdio.h>
int twice(int x) { return 2 * x; }
int square(int x) { return x * x; }
int main(void) {
int (*f)(int) = twice;
int a = f(5);
f = square;
printf("%d %d", a, f(a));
return 0;
}
- A.10 25
- B.10 100
- C.25 100
- D.10 20
Answer & explanation
Correct answer: 10 100
First twice(5) = 10. Then f points to square, and square(10) = 100.
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 →