In C, enum constants are not modifiable lvalues. For the enumeration below with explicit values, what will happen if we attempt to pre-increment MON inside printf? #include<stdio.h> int main() { enum days { MON = -1, TUE, WED = 6, THU, FRI, SAT }; printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT); return 0; }

Difficulty: Easy

Correct Answer: Error

Explanation:


Introduction / Context:
This question checks whether you recognize that enum identifiers represent constant values, not variables. Applying increment operators to constants is illegal in C.


Given Data / Assumptions:

  • enum days has MON = -1, TUE = 0, WED = 6, THU = 7, FRI = 8, SAT = 9 by standard enumeration rules.
  • Expression used: ++MON in printf.


Concept / Approach:
Increment operators require a modifiable lvalue. Enum constants are compile-time integral constants, not objects with storage that can be incremented. Therefore, ++MON is invalid and causes a compilation error.


Step-by-Step Solution:

Check operand category of MON -> constant expression, not lvalue Apply ++ to a non-modifiable operand -> constraint violation Compiler issues error; program does not compile


Verification / Alternative check:
Replacing ++MON with MON would compile and print the values -1, 0, 6, 7, 8, 9. The error arises solely from trying to modify a constant identifier.


Why Other Options Are Wrong:

  • Any numeric tuple assumes successful compilation and execution, which does not occur.


Common Pitfalls:
Treating enum names like variables or expecting them to behave like ordinary ints that can be incremented in-place.


Final Answer:
Error

More Questions from Structures, Unions, Enums

Discussion & Comments

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