1. Home
  2. Computer Science MCQs
  3. C Programming
  4. A compiler must implement an enum whose enumerators fit…

Added 30 Nov -0001

A compiler must implement an enum whose enumerators fit comfortably inside a char. What does the C standard actually require of its size?

  1. Exactly one byte, chosen so the type is large enough for the largest enumerator value
  2. Exactly sizeof(int), because every enumerator is guaranteed to have type int in C
  3. Exactly sizeof(long), because enums are stored in the widest integer type
  4. An implementation-defined choice among char, signed int and unsigned int types Correct answer

Correct answer

D. An implementation-defined choice among char, signed int and unsigned int types

13 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs