Basics Flashcards
What is an enum (Enumeration) ?
An enum is a set of correlated values.
What are enums used to?
To give a name or a key to each one of a set of values. This improves the readability of the code.
Is this syntax correct?
enum ExampleEnum
{
A, B, C
};
Yes, this syntax declares a new enum with three possible values ( A, B and C )
Is this code valid? Why / Why not?
enum ExampleEnum
{
A, B, C
};
ExampleEnum value = 5;
This code is not valid, since variables declared with an enum as a type can only contain one of the enum’s values.
Can you specify the type of an enum?
Yes, you can modify the type as long as it’s an int value (an enum can have the type “unsigned char” but can’t be of type “float”)
How can you specify the type of an enum?
Adding “: “ to the declaration.