Steve needs to ensure that a variable can only take on one of three values: RED, GREEN, or BLUE. What should he use in C++ to achieve this?
- Array
- Enum
- Struct
- Union
Steve should use an enum (enumeration) in C++ to achieve this. An enum is a user-defined data type that consists of a set of named integer constants. In this case, he can create an enum with values RED, GREEN, and BLUE, ensuring that the variable can only have one of these predefined values.
Loading...
Related Quiz
- What is a destructor used for in C++?
- In the context of function overloading, what are the possible ambiguities that might arise and how to avoid them?
- Sarah has a library of functions, and she wants to share only what the functions do, not how they do it. What should she share with others?
- In nested loops, how does the break keyword behave when used inside the inner loop?
- Michael wants to ensure that his overloaded function is chosen correctly during compile time, even in ambiguous cases. What practices should he follow?