What is the output of this C code?
#include <stdio.h> enum Color { RED, GREEN, BLUE }; int main() { enum Color c = GREEN; printf("%d", c); return 0; }
Remember that enum values start from 0 by default.
The enum Color assigns RED=0, GREEN=1, BLUE=2. So printing GREEN prints 1.
What will this program print?
#include <stdio.h> enum Status { OK = 5, WARNING = 10, ERROR = 15 }; int main() { enum Status s = WARNING; printf("%d", s); return 0; }
Check the assigned values for each enum member.
The enum WARNING is assigned the value 10 explicitly, so printing it outputs 10.
What error will this code produce?
enum Days { MON, TUE, WED = "3", THU, FRI }; int main() { enum Days today = WED; return 0; }
Enum values must be integer constants.
Enum members must be integer constants. Assigning a string literal causes a type error during compilation.
What is the output of this program?
#include <stdio.h> enum Numbers { ONE = 1, TWO, FIVE = 5, SIX }; int main() { printf("%d %d %d %d", ONE, TWO, FIVE, SIX); return 0; }
Enum values auto-increment from the previous value.
ONE is 1, TWO auto-increments to 2, FIVE is explicitly 5, SIX auto-increments to 6.
How many items are in this enum?
enum Letters { A = 3, B, C = 7, D, E };
Count all declared enum members regardless of their values.
The enum declares five members: A, B, C, D, and E.