0
0
Cprogramming~20 mins

Enum usage in C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Enum Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this enum code?

Consider the following C code using an enum. What will be printed?

C
#include <stdio.h>
enum Color { RED, GREEN, BLUE };

int main() {
    enum Color c = GREEN;
    printf("%d\n", c);
    return 0;
}
A1
B0
C2
DCompilation error
Attempts:
2 left
💡 Hint

By default, enum values start at 0 and increase by 1.

Predict Output
intermediate
2:00remaining
What value does this enum variable hold?

What value will be printed by this program?

C
#include <stdio.h>
enum Status { OK = 5, WARNING, ERROR };

int main() {
    enum Status s = ERROR;
    printf("%d\n", s);
    return 0;
}
A5
B0
C6
D7
Attempts:
2 left
💡 Hint

Enum values increment from the last explicitly set value.

Predict Output
advanced
2:00remaining
What happens when printing an enum with a wrong format specifier?

What is the output or error of this code?

C
#include <stdio.h>
enum Level { LOW, MEDIUM, HIGH };

int main() {
    enum Level l = HIGH;
    printf("%c\n", l);
    return 0;
}
APrints a character with ASCII code 2
BPrints the number 2
CCompilation error due to wrong format specifier
DRuntime error
Attempts:
2 left
💡 Hint

Enum values are integers but printing with %c prints the character for that ASCII code.

🧠 Conceptual
advanced
2:00remaining
How many items are in this enum?

Given this enum, how many distinct named constants does it contain?

C
enum Days { MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6, SUN=7 };
A0
B6
C7
D8
Attempts:
2 left
💡 Hint

Count the number of names listed inside the enum.

🧠 Conceptual
expert
2:00remaining
What error does this enum code produce?

What error will this code cause when compiled?

C
#include <stdio.h>
enum Numbers { ONE, TWO, ONE };

int main() {
    printf("%d\n", ONE);
    return 0;
}
APrints 0
BCompilation error: duplicate enum constant 'ONE'
CRuntime error
DCompilation error: missing semicolon
Attempts:
2 left
💡 Hint

Enum constants must have unique names.