In the C language, there are a total of 32 keywords, which we can divide into two categories: data type keywords and process control keywords. Among them, data type keywords can be divided into A basic data type (5), B type modification keywords (4), C complex type keywords (5) and D storage level keywords (6); and process Control keywords can be divided into A jump structure (4), B hierarchical structure (5) and C loop structure (3). The schematic diagram is as follows:
The following are some specific introductions to these keywords:
Table of contents
1. Data type keywords
1.1 A basic data type
1.1.1 void
void is used to declare a function that has no return value or no parameter. In C language and C++, if the function has no return value, the type of the function needs to be declared as void. If there is no such description, the program will report an error, and void can also be used. To declare an untyped pointer, if the function is an untyped pointer, it needs to be declared as void type.
1.1.2 char
char is used to define character data. It is one of the most common data types in C language. It can be used to store a character. The size of char is 1 byte, that is, 8bit. At the same time, char is also a kind of integer data. Special form, because the char type actually stores an integer rather than a character. ,
1.1.3 int
Int is short for "integer" in C language. It is used to define integer data, and it is also called "basic integer type". It is the most common keyword in C language. The size of the int keyword is 4 bytes, that is, 32bit. Int is usually used to represent positive integers, negative integers and 0. The range of int type variables is -2^31~2^31-1.
1.1.4 float
The single-precision floating-point type represented by float in C language belongs to the floating-point number type, and the last 6 digits of the decimal point are saved. Generally, the system uses 32 bits to store a single-precision floating-point number, of which 8 bits are used to represent the exponent and sign, and the rest 24 bits are used to represent the significand and the sign bit. The range of float is -3.40E+38~+3.40E+38.
1.1.5 double
The double-precision floating-point type represented by double in C language belongs to the floating-point number type. Compared with float, it has higher precision and can be accurate to 15 to 16 digits. Generally, the system uses 64 bits to store a double-precision floating-point number, 12 of which are sign bits and exponent bits, and the remaining 52 bits represent mantissa bits, and its value range is -1.7E+308~+1.7E+308.
1.2 B type modifier keywords
1.2.1 short
short represents a short integer type in C language, and short occupies 2 bytes, that is, 16bit. short is short for short int, and the modified int can be omitted. In C language, the range of short type variables is -2^15~+2^15.
1.2.2 long
long represents a long integer type in C language, and long occupies 4 bytes, that is, 16 bits. In the 32-bit compilation system, long and int occupy the same memory. long is the abbreviation of long int, and the modified int can be omitted. The range of long type variables is -2^31~+2^31-1.
1.2.3 signed
signed in the C language represents a signed data type, which is used to modify the integer data, and signed represents the storage method of the signed bit. In the C language, if not specified, the defined variable defaults to a signed bit, so signed is less used than unsigned.
1.2.4 unsigned
Unsigned represents an unsigned data type in C language, which is used to modify integer data, and unsigned represents the storage method of unsigned bits. Unsigned types can only represent data with bits greater than 0. If a representation has both signed and unsigned numbers, signed numbers are automatically converted to unsigned numbers.
1.3 C complex type keywords
1.3.1 struct
In C language, struct is used for structure declaration. C language uses structures to store a set of different types of data. Variables, pointers, and arrays can be declared in structures. Programmers can use structures to encapsulate some properties.
1.3.2 union
Union is used for union declaration. Union is also called union. Union is a data structure similar to structure, which allows different data types to be stored in the same memory location, but it needs to be emphasized that in union There can only be one definite value in a memory unit at a certain moment.
1.3.3 enum
In C language, enum is used for enumeration declaration. Enumeration is a basic data type in C language, which can conveniently call the required data in some larger arrays. Enumeration is a collection, and the elements in the combination are some named integers Constants are generally automatically assigned by the compiler. If the compiler defines it, it starts from 0. If it is defined by the user, it increases backwards from the defined value.
1.3.4 typedef
typedef is used to declare a type alias, which is convenient for programmers to use for some long variables. The data types that typedef can be used for include internal data types and programmer-defined data types.
1.3.5 sizeof
In C language, sizeof is used to get the size of a specific type or a variable of a specific type. The keyword sizeof obtains the storage size of the operand in bytes, where the operand can be an expression, a data type, or a variable.
1.4 D storage level keywords
1.4.1 auto
In the C language, auto is used to specify as an automatic variable, which is automatically allocated and released by the compiler, usually allocated on the stack. Automatic variables are the most commonly used variables. If the static storage class is not specifically declared, the storage space is allocated dynamically.
1.4.2 register
In C language, register is designated as a register variable. The function of register is to suggest the compiler to store the variable in the register for use. It can be suggested that the compiler use registers instead of stacks. Using register can improve efficiency.
1.4.3 static
In C language, static refers to a static variable, which is different from the storage method of global variables. This variable is allocated in the static variable area and will not be cleared with the end of the function call. If the function is called again, its value is the value after the previous call.
1.4.4 extern
extern is used to specify that the variable is an external variable , that is, it is defined in another target file, and it can be assumed that the variable is declared by another file.
1.4.5 const
In the C language, the keyword const is the abbreviation of constant. The keyword const and the keyword volative are collectively called "cv characteristics". If a variable is modified by const, then the variable cannot be changed.
1.4.6 volative
In the C language, the keyword volative and the keyword const are collectively called "cv characteristics". This keyword can remind the compiler that the variables defined can change at any time, and the compiler can directly read data from the address.
2. Process control keywords
2.1 A jump structure
2.1.1 return
return is used in the function body to indicate that a specific value is returned (if the function is of void type, no value is returned), and return also has the function of forcing the end of the function. If the return statement is executed in the function, then the function behind statements will not be executed.
2.1.2 break
The break statement is used to jump out of the current loop or switch structure. If break is used in a loop, it can be used to terminate the loop and continue to execute the statement after the loop (if it is a nested loop, break is used to jump out of the innermost loop); in the switch structure, break is used to jump out of the current case Ends the switch statement.
2.1.3 continue
In the C language, the continue language is used to end the current loop and start the next loop. It should be noted that continue just jumps out of the current loop, if this loop is not the last loop, it will not jump out of the entire loop.
2.1.4 goto
In C language, goto means an unconditional jump statement. The goto statement can ignore any situation. After executing the goto statement, the program will jump to execute the statement after the specified identifier, but the disadvantage of using the goto keyword is that it will make the program become Complicated and not easy to maintain.
2.2 B branch structure
2.2.1 if
In C language, the if statement represents a conditional statement. When the condition is met, execute the content that satisfies the condition; when the condition is not established, the content of the department will not be executed.
2.2.2 else
The else statement expresses the negation branch of the conditional statement. The else statement is used in conjunction with the if statement. When the condition of the if statement is not satisfied, the else statement is executed; at the same time, the else can also be combined with the if statement to form an else if statement, which means that if the judgment of the if does not pass, then the following else if statement is performed. If The else if statement satisfies the condition, then executes the current statement, if not, it does not execute.
2.2.3 switch
switch is used for multiple branch statements. Switch can meet the multi-branch problem in practical problems. If there are many nested if and else, the readability will be reduced. You can directly use switch to select multi-branch.
2.2.4 default
In the C language, default is equivalent to "other" in the multiple branch statement. If the switch statement contains the default statement, then if none of the previous cases satisfy the conditions, the default statement will be executed.
2.3 C loop structure
2.3.1 for
In C language, the keyword for is used for the for loop, the form of the for loop is for (expression 1; expression 2; expression 3), if both expression 1 and expression 2 meet the conditions, then execute the for loop The embedded statement executes expression 3 again.
2.3.2 while
In C language, the keyword while is used in while loop and do-while loop. In the while loop, if while (expression), if the expression in the while satisfies the condition, execute the embedded statement in the while loop and verify the next loop condition.
2.3.3 do
In the C language, the keyword do is combined with the keyword while to form a do-while loop. In the do-while loop, the embedded statement of do-while is executed first, and the condition is verified, and the do-while loop is executed at least once.