Basics Flashcards

1
Q

What is an enum (Enumeration) ?

A

An enum is a set of correlated values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are enums used to?

A

To give a name or a key to each one of a set of values. This improves the readability of the code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is this syntax correct?

enum ExampleEnum
{
A, B, C
};

A

Yes, this syntax declares a new enum with three possible values ( A, B and C )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Is this code valid? Why / Why not?

enum ExampleEnum
{
A, B, C
};

ExampleEnum value = 5;

A

This code is not valid, since variables declared with an enum as a type can only contain one of the enum’s values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can you specify the type of an enum?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you specify the type of an enum?

A

Adding “: “ to the declaration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly