enum

The enum keyword is used to declare a enum type variable.

Syntax

The syntax is as follows:

enum {value1,value2,...valuen} var[=initializer];

The var here must be an legal variable name.

Scope

It is used in the variable declaration.

Semantics

Declare an enum type variable. An enum type variable must be equal to one of the pre-defined values. The pre-defined values are constant so it is recommended to use uppercase letters.

Examples

//lights can only be: RED, AMBER or GREEN.

enum {RED, AMBER, GREEN} lights;

enum {ON, OFF} switch;

normal state PowerOff{

switch=#OFF;

}

 

 


@2020-2022 Hao Wu. All rights reserved. Last update: May 1, 2022