Question 12
Back to Exercise
What is the output of the following program, compiled as C23?
#include <stdio.h>
int up(int x) { return x + 10; }
int down(int x) { return x - 1; }
int main(void) {
typeof(up) *steps[] = {up, down, down};
typeof(steps[0]) first = steps[0];
int v = first(0);
for (int i = 1; i < 3; i++)
v = steps[i](v);
printf("%d %zu\n", v, sizeof steps);
return 0;
}
- A 8 24 Correct
- B 10 24
- C 8 3
- D 9 24
Correct Answer: Option A
typeof(up) * is a pointer to a function like up, so steps is an array of 3 function pointers (24 bytes). 0 + 10 − 1 − 1 = 8.
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!