Enumerations in C: determine the printed integral values for three students’ statuses.\n\n#include <stdio.h>\n\nint main()\n{\n enum status { pass, fail, absent };\n enum status stud1, stud2, stud3;\n stud1 = pass;\n stud2 = absent;\n stud3 = fail;\n printf("%d %d %d\n", stud1, stud2, stud3);\n return 0;\n}\n

Difficulty: Easy

Correct Answer: 0 2 1

Explanation:


Introduction / Context:
This checks understanding of default numbering of enum constants in C and how assigning them to variables results in specific integer outputs with printf.


Given Data / Assumptions:

  • enum status defines pass, fail, absent in that order with no explicit values.
  • Default enumeration starts at 0 and increments by 1.
  • Assignments: stud1 = pass, stud2 = absent, stud3 = fail.


Concept / Approach:
With no explicit assignments, pass = 0, fail = 1, absent = 2. The program prints the underlying integer values of the enumerators assigned to stud1, stud2, and stud3.


Step-by-Step Solution:

Derive values: pass = 0; fail = 1; absent = 2.Substitute: stud1 = 0, stud2 = 2, stud3 = 1.printf prints: 0 2 1.


Verification / Alternative check:
Adding explicit values (e.g., pass = 10) would shift subsequent values. With defaults, the simple 0/1/2 sequence applies.


Why Other Options Are Wrong:

  • 0 1 2: Puts absent as 1; incorrect ordering for the given assignments.
  • 1 2 3: Assumes start at 1 and increments; not how C enumerations default.
  • 1 3 2: Not consistent with any default mapping.


Common Pitfalls:
Mixing up the order of printing with the declaration order, or assuming enums start at 1 by default.


Final Answer:
0 2 1

More Questions from Structures, Unions, Enums

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion