0
0
Cprogramming~5 mins

Enum declaration - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an enum in C?
An enum is a user-defined type in C that consists of named integer constants. It helps make code more readable by giving names to sets of related values.
Click to reveal answer
beginner
How do you declare a simple enum for days of the week in C?
You declare it like this:<br>
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
Click to reveal answer
beginner
What values do enum members get by default if not assigned explicitly?
By default, the first member gets the value 0, and each following member gets the previous member's value plus 1.
Click to reveal answer
intermediate
Can you assign specific integer values to enum members? Give an example.
Yes, you can assign specific values. Example:<br>
enum Colors { Red = 1, Green = 5, Blue = 10 };
Click to reveal answer
beginner
How do you use an enum variable in C?
First declare a variable of the enum type, then assign one of the enum members to it. Example:<br>
enum Days today = Monday;
Click to reveal answer
What is the default value of the first member in an enum if not assigned?
A-1
B0
C1
DUndefined
How do you declare an enum named Fruit with members Apple, Banana, and Cherry?
Aenum Fruit = { Apple, Banana, Cherry };
Benum Fruit(Apple, Banana, Cherry);
Cenum { Fruit = Apple, Banana, Cherry };
Denum Fruit { Apple, Banana, Cherry };
If you assign Red = 3 in an enum, what value does the next member get if not assigned?
A4
BUndefined
C0
D3
Which of these is a valid enum declaration in C?
Aenum Status { OK:0, ERROR:1 };
Benum Status = (OK, ERROR);
Cenum Status { OK = 0, ERROR = 1 };
Denum Status [OK, ERROR];
How do you declare a variable named today of enum type Days?
Aenum Days today;
BDays enum today;
Cenum today Days;
DDays today;
Explain what an enum is and why it is useful in C programming.
Think about how enums help replace numbers with names.
You got /4 concepts.
    Describe how to assign specific values to enum members and what happens to subsequent members without assigned values.
    Consider how numbering works inside enums.
    You got /3 concepts.