First, the structural body
1, what is the structure of the body
2. Structure Syntax format
3, the structure of the occupied memory space
4, the structure member assigns the value
Ii. United
1, what is the Union
2. Union syntax format
Third, enumeration
1. What is Enumeration
2. Enumeration Syntax format
First, the structural body
1, what is the structure of the body
? is a data type
? Data types that are customized by the programmer
? The structure body can contain different types of members
2. Structure Syntax format
struct{
Members
} variable name;
typedef struct {
int age;
Char name[20];
}student2;//aliases
3, the structure of the occupied memory space
? Character Alignment rules
-Identify the members that occupy the largest storage space
-Allocate storage space as a unit
-Each member is stored at an offset of 0 of the number of bytes taken by the member
4, the structure member assigns the value
int main (int argc, const char * argv[]) {
struct{
int i;
Char ch;
Double D;
}s;
S.I = 10;
s.ch = ' A ';
S.D = 3.14;
printf ("%d,%c,%g\n", S.i, s.ch, S.D);
return 0;
}
Ii. United
1, what is the Union
? The usage, syntax, and structure of the Union are very similar, but the memory allocated by all members of the Union is the same block. (Only one member information can be saved, and the combined space is the value of the maximum member space)
? A union can use a piece of memory to correspond to multiple data types
? The union differs from the structure in that the structure can hold multiple member information, and the Union can only hold one member information and the last.
2. Union syntax format
typedef Union {
int age;
Char name[2];
}lianhe;
Third, enumeration
1. What is Enumeration
? Use letters to describe a set of regular values.
? The default value of the enumeration starts at 0, and each value is an integer constant
? You can modify an enumeration value only when declaring an enumeration
? Modified enumeration value = Previous enumeration value plus 1
2. Enumeration Syntax format
-enum Week {MONDAY, Tuesday, Wednesday, Thursday, FRIDAY, SATURDAY, SUNDAY};
-typedef enum {FALSE, TRUE} BOOL;
C Basic syntax-structs, unions, and enumerations