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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *