Question 12
Back to Exercise
What is the output of the following program, compiled as C23?
#include <stdio.h>
enum small : unsigned char { S0, S1 = 200, S2 };
int main(void) {
enum small x = S2;
printf("%zu %d\n", sizeof x, x);
return 0;
}
- A 1 201 Correct
- B 4 201
- C 1 2
- D Compilation error
Correct Answer: Option A
The enum's underlying type is fixed to unsigned char, so a variable of it is 1 byte. S1 is 200 and S2 follows at 201, which still fits in an unsigned char (0–255).
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!