C Language Learning Tutorial eighth chapter-Enumeration, bitwise operations (1)

Source: Internet
Author: User
Tags bitwise

Enumeration

In practical problems, the values of some variables are restricted to a limited range. For example, there are only seven days in one weeks, only 12 months a year, and six courses a week in one class, and so on. If these quantities are described as integers, the character type or other types are clearly not appropriate. For this reason, the C language provides a type called enumeration. All possible values are enumerated in the definition of the enumeration type, and the value of the variable that is described as the "enum" type cannot exceed the defined scope. It should be explained that the enumeration type is a basic data type, not a constructed type, because it can no longer be decomposed into any basic type.

Enumeration type definition and enumeration variable description

One, the general form of enumeration definition enumerated type is:
Enum enum Name
{enumeration value table};
All available values should be listed in the enumeration value table. These values are also called enumeration elements.
For example: Enum weekday
{Sun,mou,tue,wed,thu,fri,sat};
The enumeration is named weekday and has a total of 7 enumerated values, that is, seven days of the week. Any value that is described as a weekday type variable can only be one day of seven days.

Description of enumerated variables as with structs and unions, enumeration variables can also be described in different ways, that is, to define a description, and to define a description or a direct description. Where a variable a,b,c is described as the weekday mentioned above, any one of the following methods may be used:
Enum Weekday
{
......
};
Enum weekday a,b,c or as: Enum weekday
{
......
}a,b,c; or: enum
{
......
}a,b,c;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.