Register keyword
Register declares the Register variable [try to store the variable in the internal CPU Register, not absolute]
CPU reads data: memory -- register -- CPU
Although the register speed is very fast, there are limits: The register variable must be a type that can be accepted by the CPU register, meaning that the register variable must be a single value, the length must be less than or equal to the length of an integer. In addition, the register variable may not be stored in the memory, so the address of the register variable cannot be obtained using the address fetch operator.
Volatile indicates that variables can be implicitly changed during program execution.
Sizeof the memory space occupied by computing objects. This is the keyword (⊙ o ⊙ ~
[Cpp]
Int I = 0;
A) sizeof (I) B) sizeof (int) C) sizeof I D) sizeof int
Int I = 0;
A) sizeof (I) B) sizeof (int) C) sizeof I D) above sizeof int, ABC is correct, and D is incorrect.
[Note] sizeof can be omitted when the space occupied by calculation variables is large, but it cannot be omitted when the calculation type is large.
Take a look at the following exercises:
NOTE: For the value of sizeof (a), let's look at it again:
[Conclusion] Sizeof is a type input in an hour and has nothing to do with the specific value of the variable. & A, & a [0], & a [0] [0] are all addresses, so the size is 4; the type of a is char [10] [10], so it is 100. Similarly, the types of a [0] And a [1] [1] are char [10] and char respectively, so the sizes are 10 and 1 respectively.
The input here is the pointer char *, so the size is 4. If B is int [100], the input is int *.
[Summary] When the function parameter is an array, it does not pass the entire array, but an array address, that is, a pointer.
Differences between Sizeof and strlen:
Let's try again:
Sizeof calculates the struct size:
The member alignment rule is that each member is aligned to a smaller alignment parameter in the specified alignment parameter (usually the size of this type, that is, min (sizeof (item), n ). In addition, the length of the structure must be an integer multiple of all alignment parameters used.
The size of s1 is 3, and the size of s2 is 5. This indicates that the maximum alignment parameter of s1 is 1, that is, the maximum alignment parameter of s1 data members, instead of using the size of s1 as an alignment parameter.
Unsigned keyword
Let's look at an example:
Const keyword = readonly
Read-Only variables modified by Const must be initialized at the same time as defined.
Note: The case statement cannot be followed by the const variable.
Const and define
When modifying variables and arrays, you can put them before and after the types:
When modifying pointers:
The Const modifies the parameters of a function. You do not want the parameter values to change unexpectedly in the function.
Typedef keyword
Differences between Typedef and define:
Define is a macro definition, which works during pre-compilation, but is simply replaced;
Typedef is used to create an alias for the type, which takes effect during compilation.
# Define int32 static int
Define replaces all content after the second space with the first string int32.
Typedef static int int32;
Compilation error. Multiple types are declared.
Volatile keywords
Volatile tells the compiler that variables may change at any time, and the I value must be retrieved from the memory each time it is used.
Const volatile int I = 3; Is a read-only variable.
Union keyword
[Plain]
// If the return value is 1, it indicates that the mode is small. If the return value is 0, it indicates that the mode is large.
Int checkSystem ()
{
Union check
{
Int I;
Char ch;
} C;
C. I = 1;
Return (c. ch = 1 );
}
// If the return value is 1, it indicates that the mode is small. If the return value is 0, it indicates that the mode is large.
Int checkSystem ()
{
Union check
{
Int I;
Char ch;
} C;
C. I = 1;
Return (c. ch = 1 );
}
Static keywords
Modify variable
Static global variables. The scope is limited to the files defined by the variables. Other files cannot be used even if they are declared using extern. Accurately speaking, the code starting from the definition and ending at the end of the file cannot be used before the definition.
Static local variables are defined in the function body and can only be used in the function, but the lifecycle is the same as that of the file.
[Note] Static variables are initialized only once during definition. The following code:
Each time f1 is called, The I value is incremented and will not be redefined. Each time f2 is called, the j value is re-copied. Therefore, j is incremented only once.
Modifier
The scope of static functions is limited to this file (also called internal functions ).
To sum up, the keyword static has two meanings: local variables that still exist after exiting a block; global variables and functions that cannot be accessed by other files.
The memory of static variables is allocated to the stack because their size is determined during compilation.