Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C Language: What format should be used to interpret the output of enumerated variables?
C Language: What format should be used to interpret the output of enumerated variables?
In C language, enumerated variables, that is, variables defined by enum keywords, are regarded as integers or unsigned integers.

1

If there is no negative value in the enumeration variable, for example

Enumeration type

test

{

One,

b,

};

With this definition, the system will treat enumerated variables as unsigned integers, that is, unsigned.

Internationalorganizations (same as international organizations)

Type. Just use %u format when outputting.

Enumeration type

test

t

=

a;

printf("%u ",

t);

2

If there is a negative value in the enumeration variable, the system will be treated as an integer, that is, an int type. By definition

Enumeration type

test

{

a=- 199,

b,

};

When outputting, you need to use %d format:

Enumeration type

test

t

=

a;

printf("%d ",

t);

three

Because enumeration variables are generally not too large when they are written, it is rare that there are no negative numbers, that is, when they are treated as unsigned numbers, they are beyond the range of positive numbers that can be represented by signed numbers, that is, the highest bit is generally not set to 1, so it is no problem to output with% d in most cases.