Structure is a structure data type, can be understood as a custom data type by a different type of data.
Defined above the structure is defined to be on in the main.
Structure is defined format:
struct {// the name of the structure <- Structure name can not write, the write will not be unknown structure
type member name;
type member name;
...
} structure variables 1, 2 structure variables, structure variable body 3, ...;
Example:
struct nameinfo{
char name[50];
char phone[100];
int num;
};
Internal structures may be nested structure
Definition of the structure is not created in memory, when only declared in the main will be created
Declared in the main structure: struct structure variable structure;
Example:
struct nameinfo a;
It can be used as a type struct nameinfo.
You can also declare variables outside the main structure of.
struct nameinfo{
char name[50];
char phone[100];
int num;
}a,b,c,d;
Members of a structure variable assignment:
a structure member variable name = value;.
Example:
a.num = 100;.
If the members of the structure type is char or char * string, you must first apply for memory, to use sprintf or strcpy be assigned. If char [] is not the type of application memory, direct use sprintf or strcpy assignment.
example:
strcpy(a.name,"xiaoming");
Note: The internal structure if the nested structure, but does not create an instance of the sub-structure, the internal structure of the variable definition will be treated as a member variable parent structure.