 .TH enum "" "" "C Keyword"
.PC "Declare a type and identifiers"
.PP
An
.B enum
declaration is a data type whose syntax resembles those of the
.B struct
and
.B union
declarations.
It lets you enumerate the legal value for a given variable.
For example,
.DM
	enum opinion {yes, maybe, no} GUESS;
.DE
.PP
declares type
.B opinion
can have one of three values:
.BR yes ,
.BR no ,
and
.BR maybe .
It also declares the variable
.B GUESS
to be of type
.BR opinion .
.PP
As with a
.B struct
or
.B union
declaration, the tag (\fBopinion\fR in this example) is optional;
if present, it may be used in subsequent declarations.
For example, the statement
.DM
	register enum opinion *op;
.DE
.PP
declares a register pointer to an object of type
.BR opinion .
.PP
All enumerated identifiers must be distinct
from all other identifiers in the program.
The identifiers act as constants and can be used
wherever constants are appropriate.
.PP
\*(PN assigns values to the identifiers from left to right,
normally beginning with zero and increasing by one.
In the above example, the values of
.BR yes ,
.BR no ,
and
.B maybe
are set, respectively, to one, two, and three.
The values often are \fBint\fRs, although if the range of values is small
enough, the
.B enum
will be an
.BR "unsigned char" .
If an identifier in the declaration is followed by an equal sign and a
constant, the identifier is assigned the given value,
and subsequent values increase by one from that value; for example,
.DM
	enum opinion {yes=50, no, maybe} guess;
.DE
.PP
sets the values of the identifiers
.BR yes ,
.BR no ,
and
.B maybe
to 50, 51, and 52, respectively.
.SH "See Also"
.Xr "C keywords" c_keyword
.br
\*(AS, \(sc6.5.2.2
