Considering the following enum in C++, what will be the value of Sunday?
enum days (Sunday, Monday=5, Tuesday, Wednesday=7}
Answers
Answered by
3
Answer:
The value of Sunday can be 4
Answered by
0
Enum or enumeration is a data type consisting of named values like elements, members, etc., that represent integral constants.
- It contains fixed set of named integral constants.
- Their main use is in declaration of flags.
- The syntax to declare enumerations is as follows:
- enum <name> { named_constant1, named_constant2,...};
- e.g. enum directions ( NORTH, SOUTH, EAST and WEST);
- Here direction is the name of the enum and NORTH, SOUTH, EAST and WEST are its named values.
- The default value of NORTH is 0, SOUTH is 1, EAST is 2 and WEST = 3. i.e. values are assigned in incremental order starting with 0.
- One can assign values to enum. for e.g. enum season { summer=5, monsoon=2, winter=9 };
- Here summer has value 5, monsoon has value 2 and winter the value 9.
- One can use a combination of unset and set values. for e.g. enum directions { NORTH=5, SOUTH, EAST and WEST=2};
- This sets NORTH to 5, since SOUTH has no set value its value is set to value of NORTH+1 = 5+1= 6, so EAST is set to 7 and WEST to 2.
- The current question enum days (Sunday, Monday=5, Tuesday, Wednesday=7};
- Sunday has no set value, so it is given default value of 0, Monday will be set to 5, Tuesday will have value Monday+1 = 5+1 = 6 and Wednesday has value 7.
- The value of Sunday is 0.
#SPJ2
Similar questions
Math,
5 months ago
English,
5 months ago
History,
5 months ago
Physics,
10 months ago
Social Sciences,
1 year ago