Several forms of the definition of C-language structural body

Source: Internet
Author: User

Transfer from 798973271, the most common definition method: Define the structure of data, at this time the structure is equivalent to a type, such as int, if you want to use this struct, method with int

struct Data
{
char AA;
char BB;
Char cc;
int DD;

};

struct data sum1, sum2;

2, define the structure of the data at the same time, define the need to use the structural body variable sum1,sum2. If you need to define a struct variable later, the method is the same as 1

struct data
{
Char AA;
char BB;
Char cc;
int DD;
}SUM1, sum2;

struct data sum3;

3, when defining the structure, the structure name is default, and the structure variable sum1,sum2 is defined. But you can no longer define struct variables!

struct
{
Char AA;
char BB;
Char cc;
int DD;
}SUM1, sum2;

struct SUM3; <-Compiler Error

4, using typedef to define the structure, define the structure of data, using TypeDef, this form is almost not used, and then define the structure of the variable, still need to add a struct, otherwise the compiler Error!

typedef struct DATA

{
Char AA;
char BB;
Char cc;
int DD;
};

struct data sum3;


5, using typedef to define the structure of the same time, to the data structure alias data, the subsequent definition can not use the struct data, directly using data.

typedef struct DATA
{
Char AA;
char BB;
Char cc;
int DD;
}data;

struct data sum3; <-available, but not recommended

DATA sum1; <-most common way

6, when using typedef to define the structure, omit the structure of the first alias data, directly behind the data, using the same method as 5.

typedef struct
{
Char AA;
char BB;
Char cc;
int DD;
}data;

DATA sum3;

Several forms of the definition of C-language structural body

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.