A compiler must implement an enum whose enumerators fit comfortably inside a char. What does the C standard actually require of its size?
Correct answer
D. An implementation-defined choice among char, signed int and unsigned int types
13 views
D. An implementation-defined choice among char, signed int and unsigned int types
13 views
Enumerated types must be compatible with char, a signed integer type or an unsigned integer type, and the choice is implementation-defined, so sizeof may differ between compilers. The enumerators themselves have type int, which is why they can be printed with %d. C++ also leaves the underlying type implementation-defined but allows it to be fixed with enum class : uint8_t.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.