enumerated constantsenumerated constants enable


Enumerated Constants

Enumerated constants enable the creation of new types and then explain variables of these types so that their values are restricted to a set of possible values.

e.g.

 enum Colour{RED, BLUE, GREEN, WHITE, BLACK};

Colour is the name of an enumerated data type. It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the value 1 and so on.

- Each enumerated constant has an integer value. If the program doesn't specify or else, the first constant will have the value 0, the remaining constants will count up by 1 as compared to their predecessors.

- Any of the enumerated constant can be initialised to have a particular value, though; those that are not initialised will count upwards from the value of previous variables.

e.g.

enum Colour{RED = 100, BLUE, GREEN = 500, WHITE, BLACK = 1000};

The values assigned will be RED = 100,BLUE = 101,GREEEN = 500,WHITE = 501,BLACK = 1000

 

  • You can explain variables of type Colour, but they can hold only one of the enumerated values. In our case RED,BLUE,GREEEN,WHITE,BLACK .
  • You can declare objects of enum types.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: enumerated constantsenumerated constants enable
Reference No:- TGS0309304

Expected delivery within 24 Hours