First,Registervariables
keyword regiter requests the compiler to make the variables available to the CPU as much as possible in the register. Here are some points to note.
- The register variable must be a type that can be accepted by the CPU register, which usually means that the register variable must be a single value, and its length should be less than or equal to the length of the integral type. However, some machine registers can also store floating-point numbers.
- The register variable may not be stored in memory, so the accessor operator "&" cannot be used.
- Only local variables and formal parameters can be used as register variables, not global variables.
- Static variables cannot be defined as registers.
Second,Static1. Modifier variables (local and global variables)1.1.Static global Variables:
allocates memory in the global data area; uninitialized static global variable is automatically initialized by the program to 0 (the value of the automatic variable is random, unless it is explicitly initialized) Scope is limited to the file defined by the variable the.
the difference between global variables and global static variables :
(1 ) Global variables are global variables that are not explicitly decorated with static, but global variables The default is static, the scope is the entire project, the full-board variable defined within one file , and the global variable can be used in another file through the declaration of the extern global variable name .
( 2 ) a global static variable is a global variable that is explicitly decorated with static, the scope is the file in which the other file is used, and the extern declaration is not used.
1.2. Static local Variables2, static functions
Before the return type of the function is prefixed with the static keyword, the function is defined as a static functor . A static function differs from a normal function in that it can only be seen in the file in which it is declared and cannot be used by other files. In other files, you can define a function of the same name , and there will be no conflict.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C keyword Register, extern, static, some summary