In the way we structure how to correctly defined 4

C language structure is often used in the structure must therefore learn, whether you are doing an embedded microcontroller or C language development, we have a definition of the structure to be a beginning, simply a few, there will be detailed below to provide reference materials to explain.

1. The first type of structure is defined, then the definition of structure variables.

Student {struct 
    char NO [20 is]; // Science No. 
    char name [20]; // name 
     char sex [5]; // Gender 
    int age; // Age 
};              
struct Student STU1, STU2; 
// this case STU1 , stu2 structure variables as student

  2. The definition of the structure also defines the type of structure variables.

Student {struct 
    char NO [20 is]; // Science No. 
    char name [20]; // name 
    char sex [5]; // Gender 
    int age; // Age 
} stu1, stu2;

  

At this time, we can continue to define student structure variables, such as:

struct student stu3;

3, do not specify the name of the type definition of the structure variables directly

{struct 
    char NO [20 is]; // Science No. 
    char name [20]; // name 
    char sex [5]; // Gender 
    int age; // Age 
} stu1, stu2;  

  

Generally do not use this method, since the direct definition of the structure variables STU1, after STU2, can no longer continue to define the type of variable.

4, member variables defined using typedef struct

typedef struct stdudent
 
{
       char name[20];
       int age;
}student_t;

  

The above code structure defines a variable type, which has two names: first name is struct student; second type name is student_t.

After defining the following two methods may be defined with a structure variable

The first: struct student student_1; // defines the structure of the variable student_1

The second: student_t student_1 // define a structure variable of a student_1

 

- Starters: C data type sold - structure popularization and application -

http://www.makeru.com.cn/live/5413_1909.html?s=45051

Guess you like

Origin www.cnblogs.com/QianD/p/11126004.html