C-language common Union and enumeration type Enum

Source: Internet
Author: User

The Memory Length occupied by struct variables is the total memory length occupied by each member. Each member occupies its own memory unit.

The Memory Length occupied by the shared body variable is equal to the longest member length.

 

Note:

1. the members that are last stored when a member plays a role in a shared object variable is saved to a new member, and the original members become ineffective.

2. You cannot take the shared body variable as a function parameter or bring the function back to the shared body variable, but you can use the pointer of the variable.

 

Enumeration type: Enum weekday {sun, Mon, Tue, WND, Thu, Fri, sat };

Note:

1. In C compilation, enumeration elements are processed according to constants, so enumeration constants are called. They are not variables and cannot be assigned values.

2. Enumeration elements are constants, which have values. C language compilation makes their values 0, 1, 2, and so on in the defined order ,....

You can also change the value of the enumerated element.ProgramSpecified by members, such:

Enum weekday {sun = 7, MON = 1, Tue, wed, Thu, Fri, sat} workday, week_end;

Define sun = 7, MON = 1, and then add 1 in sequence. Sat is 6.

3. An integer cannot be directly assigned to an enumerated variable.

Values can be assigned only when forced type conversion is performed. For example, workday = (Enum weekday) 2;

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.