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