Build your own data types --C structure induction

First, the establishment of the structure type

1, affirm the structure type

struct structure name 
{ 
    members of the table column (Type name members;); 
}; 

for example: 
struct the Person 
{ 
    char name;
     int Age;
    char Sex; 
}; 
// defines a structure type - struct the Person

struct keywords, can not be omitted 
type of structure, like other types, and other types having the same position in the c procedures, as if int (integer type) char (character type) as

Zu: structure name can be freely named members of the table columns can be freely defined by the reality. Writing fixed format, content customization.

2, definition of the structure type variable

Introduction:
1) when the program runs only on variables operations without the type of operation, (for example, when you conducted operations on int double assignment it, right) so we must first define a variable, then in order to manipulate it.

2) compile time type is not allocated space on will only allocate storage for variables.

3) the members of the structure may be used alone, it corresponds to the normal role and status variables.

4) to follow: to define the type of structure, after the definition of the structure variables.

Definition of the structure variable three methods:

1) the structure type name variable name;

  (Similar: type name variable name;)

struct     Student 
{ 
   char name;
    int Age;    
}; // definition of the structure type 

struct Student student1, student2; // define student1, student2 two structure variable 

struct Student Students. [ . 5 ]; // define an array of structures a length of 5

Structure type can also define an array.

2) stated structure also defines the type of variable

struct     Student 
{ 
   char name;
    int Age;    
} studen1, student2; // defined struct types Student t This structure also defines studen1, student2 two Student struct structure variable 

struct structure name 
{ 
  variables listed;   
} variable watches column; 

// array of structures can be so defined
struct     Student
{
   char name;
   int Age;  
} studens [5];
// define an array of structures, a length of 5

(Struct name structure) referred to collectively as a structure type.

3) is not directly defined type names defined variable structure type

Nameless structure can not define such a structure variable again.

strcut 
{ 
    char name;
     int Age; 
} student1, STUDENT2;

the same meaning as above //

Zu: the method defined way of little significance, use very little.

3, the structure and use of initialization variables

This part is relatively simple, it does not describe any one c language textbook will explain.

4, do not explain the structure pointer.

 

Guess you like

Origin www.cnblogs.com/gti2baby/p/11332565.html