Enumeration of C languages

Source: Internet
Author: User

Definition of enum type

the general form of an enumeration type definition is:

Enum Enum Name {enumeration value list};

Lists all available values in the enumeration values list. These values are also known as enumeration elements, the enumeration values are constants, not variables, and the enumeration elements themselves are defined by the system as a numeric value that represents an ordinal, defined as 0,1,2 in the order of 0.

For example:

Enum weekday{Sunday, Monday, Tuesday, Wednesday, Thursday, Fridar, Satur Day};

define enum variable enum WeekDay enumeration variable name;

Define enum variable enum WeekDay oneday = Sunday;

Full code:

#include  <corefoundation/corefoundation.h>int main (int argc, const char *  argv[]) {    enum weekday{        sunday ,        monday,         tuesday,        wednesday,         thursday,        fridar,         saturday    };        //  Defining enumeration variables     enum WeekDay oneDay = sunday;         if  (oneday == sunday | |  oneday == saturday)  {        printf ("Rest day \ n");     }else{        printf ("Business day \ n");     }        printf ("Numerical Value:%d\n", OneDay);     return 0;}

The output results are as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/46/6C/wKioL1PyLOGAyk1sAABc4TO58t8655.jpg "title=" Enum uses. png "alt=" wkiol1pylogayk1saabc4to58t8655.jpg "/>

This article is from the "7803002" blog, please be sure to keep this source http://7813002.blog.51cto.com/7803002/1541820

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.