0
0
Cprogramming~5 mins

Enum usage in C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an enum in C?
An enum in C is a way to name a set of integer constants. It helps make code easier to read by giving meaningful names to numbers.
Click to reveal answer
beginner
How do you define an enum for days of the week in C?
You write:
enum Day { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
This creates names for numbers starting at 0.
Click to reveal answer
intermediate
Can you assign specific numbers to enum members?
Yes. You can set values like
enum Color { Red = 1, Green = 5, Blue = 10 };
. Members without assigned values get the next number after the previous one.
Click to reveal answer
beginner
How do you use an enum variable in C?
Declare a variable with the enum type, like
enum Day today;
. Then assign a value:
today = Monday;
. It stores the integer for Monday.
Click to reveal answer
beginner
What is the default starting value of the first enum member if not assigned?
The first enum member starts at 0 by default. Each next member increases by 1 unless specified otherwise.
Click to reveal answer
What value does the first member of an enum have if not explicitly assigned?
A-1
B1
C0
DUndefined
How do you declare an enum variable named color of type enum Color?
Aenum Color color;
BColor enum color;
Cint color;
Dvar color = enum Color;
If you define enum Fruit { Apple = 3, Banana, Cherry };, what is the value of Cherry?
A3
B5
CUndefined
D4
Which of these is a benefit of using enums?
AAutomatically creates functions
BSlows down the program
CAllows floating point values
DMakes code easier to read by using names instead of numbers
Can enum members have duplicate values?
AYes, but it is not recommended
BNo, it causes a compile error
COnly if they are consecutive
DOnly if they are the first two members
Explain what an enum is and how it helps in C programming.
Think about how enums replace numbers with names.
You got /3 concepts.
    Describe how to assign specific values to enum members and what happens to members without assigned values.
    Consider how numbering works inside enums.
    You got /3 concepts.