Double: Declare a double-precision variable or function.
Int: Declare an integer variable or function.
Struct: Declare a structural variable or function.
Break: jump out of the current loop.
Else: Negative branch of conditional statement (used with if)
Long: Declare a long integer variable or function.
Switch: used to switch statements.
Case: switch statement branch
Enumeration: Declaring Enumeration Type
Registers: Declaring Accumulator Variable
Typedef: an alias used for data types (of course, there are other uses)
Char: Declare a character variable or function
Extern: The declared variable is being declared in another file (it can also be regarded as a reference variable).
Return: The subroutine returns a statement (with or without parameters).
Union: declare union data type.
Const: declare a read-only variable
Float: Declare a floating-point variable or function.
Short: Declare a short integer variable or function.
Unsigned: Declare an unsigned type variable or function.
Continue: End the current cycle and start the next cycle.
Agree: a circular statement (meaning beyond words)
Signed: Life has a signed type variable or function.
Void: Declare that a function has no return value or no parameters, and declare an untyped pointer (basically these three functions).
Default: "Other" branch in switch statement
Goto: unconditional jump statement
Sizeof: Calculate the data type length
Volatile: indicates that variables can be changed implicitly during program execution.
Do: the loop body of the loop statement
While: loop condition of loop statement
Static: declare a static variable.
If: conditional statement
1) automatic
This keyword is used to declare that the lifetime of variables is automatic, that is, variables that are not defined in any class, structure, enumeration, union and function are regarded as global variables, while variables defined in functions are regarded as local variables. This keyword is not easy to write because all variables are auto by default.
(2) Registration
This keyword commands the compiler to store variables in CPU internal registers as much as possible, instead of accessing them through memory addressing, so as to improve efficiency.
(3) Static
Two common uses:
1 & gt; Calculate the number of times the function is called;
2> Reduce the overhead of creating and allocating local arrays. Creating and allocating variables requires some processor overhead, especially for storage types that contain more elements, such as arrays. In some functions that contain many variables and are frequently called, some arrays can be declared as static types to reduce the overhead of establishing or initializing these variables.
Detailed description:
1 & gt; The variable will be placed in the global storage area of the program, so that the original assignment can be maintained in the next call. This is the difference between it and stack variables and heap variables.
2> variables use static to tell the compiler that they are only visible within the scope of variables. This is the difference between it and global variables.
3> When modifying a global variable with static, the scope of the global variable is changed, so that it cannot be restricted to the current file by other programs extern, but its storage location is not changed, and it is still in the global static storage area.
Precautions for use:
1 & gt; If you only access global variables in a single C file, you can modify them into static global variables to reduce the coupling between modules.
2> If the global variable is only accessed by a single function, it can be changed into a static local variable of this function to reduce the coupling between modules;
3> When designing and using functions to access dynamic global variables, static global variables and static local variables, we need to consider the re-entry problem (as long as the input data are the same, the same output will be produced).
(4) Constant
Everything modified by const is forcibly protected, which can prevent unexpected changes and improve the robustness of the program. It can decorate parameters, return values and even the definition body of functions.
Function:
1 & gt; Modify input parameters
A for input parameters with non-internal data types, in order to improve efficiency, the mode of "value passing" should be changed to "constant reference passing". For example, change void Func(A a) to Void Func(Const A & amp; Answer.
B for input parameters with internal data types, do not change the mode of "value passing" to "constant reference passing". Otherwise, the efficiency cannot be improved and the understandability of the function will be reduced. For example, void Func(int x) should not be changed to Void Func (const int&; x).
2> Decorate the return value of a function with const.
A. If the function return value of "pointer passing" mode is decorated with const, the content of the function return value (i.e. pointer) cannot be modified, and the return value can only be assigned to the same type pointer decorated with const.
For example: constchar * getstring (void);
Compilation errors occur in the following statements:
char * str = GetString(); //Cannot convert from' const char *' to' char *';
The correct usage is:
const char * str = GetString();
B. If the return value of the function is "value transfer mode", since the function will copy the return value to the external temporary storage unit, adding const decoration has no value. If you don't write the function int GetInt(void) as const int GetInt(void).
3> In the declaration of a const member function, the const keyword can only be placed at the end of the function declaration, indicating that such members do not modify the object.
Description:
Constant type m; //The modified m is immutable.
Example:
Typedef char * pStr// new type pStr
char string[4]= " ABC ";
const char * p 1 = string;
p 1++; //Correct, the above modification is * P 1, and P 1 is a variable.
const pStr p2 = string
p2++; //Error, p2 was modified above, p2 is immutable, and *p2 is mutable.
Similarly, const will not be confused when judging by this principle when modifying the pointer.
Const int * value; //* values are immutable and changeable.
Int* constant value; The//value is immutable, and the * value is changeable.
Const (int *) value; //(int *) is a type with immutable values and variable * values.
//Logically, the compilation fails, and tydef int * NewType is required.
Const int* constant value; //* value, the value is immutable.
(5) instability
It means that the value of a variable may be changed externally, and the optimizer must carefully re-read the value of the variable every time it uses it, instead of using the backup stored in the register. It can be applied to basic types, such as int, char, long ... and the structure of C and the class of C++. When a structure or class object is decorated with volatile, all members of the structure or class will be regarded as volatile.
This keyword is often used in a multithreaded environment, because when writing a multithreaded program, the same variable may be modified by multiple threads, and the program synchronizes the threads through this variable.
Simple example:
Dword _ _ stdcall threadfunc (lpvoid signal)
{
int * int signal = reinterpret _ cast(signal);
* int signal = 2;
while(*intSignal! = 1)
Sleep (1000);
Returns 0;
}
When the thread starts, it sets the intSignal to 2, and then waits in a loop until the intSignal is 1 and exits. Obviously, the value of intSignal must be changed externally, otherwise the thread will not quit. However, the thread will not quit when it is actually running, even if the external value is changed to 1, just look at the corresponding pseudo-assembly code.
Moving axis, signal
Label:
If (ax! = 1)
Go to tab
For the C compiler, it doesn't know that this value will be modified by other threads. Naturally, it is cached in a register. C compiler has no concept of thread, so volatile is needed at this time. Volatile means that the value can be changed outside the current thread. In other words, we need to add the volatile keyword before intSignal in threadFunc. At this point, the compiler knows that the value of the variable will change externally, so it will be re-read every time the variable is accessed, and the loop will become as shown in the following pseudo code:
Label:
Moving axis, signal
If (ax! = 1)
Go to tab
Note: A parameter can be constant, changeable or changeable, because it may be changed unexpectedly. It is a constant because programs should not try to modify it.
(6) External personnel
Extern means "foreign" ... its function is to tell the compiler that this variable may not exist in the current file, but it must exist in the source file or the output of the Dll in the project.
In addition: keywords in C language