Challenge - 5 Problems
Enumeration Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Purpose of Enumerations in C
Why do programmers use enumerations (enum) in C?
Attempts:
2 left
💡 Hint
Think about how naming values helps when reading code.
✗ Incorrect
Enumerations let you give names to integer values. This makes code easier to read and understand because you use meaningful names instead of numbers.
❓ Predict Output
intermediate1:30remaining
Output of Enum Values
What is the output of this C code snippet?
C
#include <stdio.h> enum Color { RED, GREEN, BLUE }; int main() { enum Color c = GREEN; printf("%d", c); return 0; }
Attempts:
2 left
💡 Hint
By default, enum values start at 0 and increase by 1.
✗ Incorrect
In C, the first enum value RED is 0, GREEN is 1, and BLUE is 2. So printing GREEN prints 1.
❓ Predict Output
advanced1:30remaining
Enum with Custom Values Output
What will this program print?
C
#include <stdio.h> enum Status { OK = 5, WARNING = 10, ERROR = 15 }; int main() { enum Status s = WARNING; printf("%d", s); return 0; }
Attempts:
2 left
💡 Hint
Look at the assigned values in the enum.
✗ Incorrect
The enum assigns WARNING the value 10 explicitly, so printing it outputs 10.
🧠 Conceptual
advanced1:30remaining
Benefits of Using Enumerations
Which of the following is NOT a benefit of using enumerations in C?
Attempts:
2 left
💡 Hint
Think about what enums do and what they don't do.
✗ Incorrect
Enumerations do not allocate memory for large data structures. They only define named integer constants.
❓ Predict Output
expert2:00remaining
Enum and Switch Statement Output
What is the output of this C program?
C
#include <stdio.h> enum Direction { NORTH = 1, EAST, SOUTH = 5, WEST }; int main() { enum Direction d = WEST; switch(d) { case NORTH: printf("North"); break; case EAST: printf("East"); break; case SOUTH: printf("South"); break; case WEST: printf("West"); break; default: printf("Unknown"); } return 0; }
Attempts:
2 left
💡 Hint
Check the enum values and which case matches WEST.
✗ Incorrect
WEST is assigned the value 6 (one more than SOUTH's 5). The switch matches case WEST and prints "West".