0
0
Cprogramming~20 mins

Enum declaration - 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
Output of enum variable assignment

What is the output of this C code?

C
#include <stdio.h>

enum Color { RED, GREEN, BLUE };

int main() {
    enum Color c = GREEN;
    printf("%d", c);
    return 0;
}
A0
B1
CCompilation error
D2
Attempts:
2 left
💡 Hint

Remember that enum values start from 0 by default.

Predict Output
intermediate
2:00remaining
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;
}
A0
B5
C15
D10
Attempts:
2 left
💡 Hint

Check the assigned values for each enum member.

🔧 Debug
advanced
2:00remaining
Identify the error in enum declaration

What error will this code produce?

C
enum Days { MON, TUE, WED = "3", THU, FRI };

int main() {
    enum Days today = WED;
    return 0;
}
ANo error, compiles fine
BWarning: implicit conversion from string to int
CTypeError: enum member must be integer constant
DSyntaxError: enum member cannot be a string
Attempts:
2 left
💡 Hint

Enum values must be integer constants.

Predict Output
advanced
2:00remaining
Enum auto-increment behavior

What is the output of this program?

C
#include <stdio.h>

enum Numbers { ONE = 1, TWO, FIVE = 5, SIX };

int main() {
    printf("%d %d %d %d", ONE, TWO, FIVE, SIX);
    return 0;
}
A1 2 5 6
B1 1 5 6
C1 2 5 5
D1 2 6 7
Attempts:
2 left
💡 Hint

Enum values auto-increment from the previous value.

🧠 Conceptual
expert
2:00remaining
Number of items in enum

How many items are in this enum?

C
enum Letters { A = 3, B, C = 7, D, E };
A5
B4
C3
D6
Attempts:
2 left
💡 Hint

Count all declared enum members regardless of their values.