The "C" enumeration, and the differences between enumerations and struct bodies

Source: Internet
Author: User

Enumeration of the actual meaning of the meaning of Chinese is not much similar to the place, and it is easy to remind people of the poor lift.

After you've learned the basics, you're done with a few basic data types, huh?

The poor lift ... Yuck, enumerations and structs are similar in structure

struct stuent        {        int age ;         float height;        };
enum {     FIR,     SCD,      THD}; 

But many different, as follows

1, the definition of a struct is defined as a data type , and then a struct variable is declared , the struct variable itself can only be assigned to another struct variable, and two structure variables must be the same structure, but the structure variable Variables within the range can be assigned. And the identifier used by the struct variable declaration does not occupy the space of the identifier of the variable , but it takes up a space with the common body, enumeration, and struct.

struct student Amy; int Amy =3;p rintf ("", Amy.age, Amy);

This is possible.

Enumerations also define a data type , but the declared enumeration variable has little resemblance to the struct variable. An enumeration variable is an integer variable, or it can be assigned a value (this differs from Baidu)

The identifier used by the enumeration variable declaration takes up space for the identifier of the variable . It may be that the storage class will overwrite, and the same storage class would conflict (usually, the code block will give me an error).

2, the member of an enumeration can only be an integer variable, so there is no need to declare the data type of the member, but the struct needs to be declared because the member of the struct can be a variable, an array, a pointer, a struct, an enumeration variable, or a common body.

3, enumerations, structs are defined data types, but structs are not actually useful after they are defined, only after declaring struct-body variables.

The identifier used by its members after the enumeration is defined takes up space for the identifier of the variable . And even if the enumeration variable is not defined, it can be used as a constant when its members are taken out.

4, the function of the structure in C language is not on the structure variables, but the internal members of the structure variables, the structural variables have little effect.

Enumerations are mostly enumerated constants, but variables can still be used when a common variable is available.

The "C" enumeration, and the differences between enumerations and struct bodies

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.