LearnFrenzy
Sign in Take a free test

Structures, Unions, Enums · Predict the Output · Question 12

C23 enum : unsigned char – size and value Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What is the output of the following program, compiled as C23?

main.c
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links