Register:
Define variable is register save, not write to memory
- The address cannot be taken because it is on the register
- Unable to save data stored in information and BSS segments
- registers are equivalent to memory cache, which increases access speed, but how many of them can be saved by the CPU , and the excess will be ignored.
Static:
Static modifier variables:
- Static modifies the local variable, initializes it the first time it encounters it, and stores the data in the database segment, so the function stack pin is not destroyed when it is rolled back and destroyed after the program ends.
- Static modifier global variable: Unlike global variables, other files cannot find the address of this variable symbol at link time.
- In C + + , global variables affect encapsulation, are implemented using static data members defined within a class through scope access, and therefore do not have the same name as global variables (typically defined within a class, and are initialized outside of the class).
- A static decorated data member in C + + can no longer be initialized with a constructor, and needs to be initialized at the time of definition. Only static normally shaped variables can be initialized within a class (static const int).
Static modifier function:
- The function plus static in C language declares that this function cannot be found at link time, only visible in this file.
- inC + +, thestatic decorated function does not Pass in the this pointer, so it cannot access the object's non- static data members.
NULL:
in C language #define NULL ( void* ) 0 p = = NULL p = = 0 c++ #define NULL 0 nullptr null
Switch and case:
- Attention Remember break
- The floating-point number is not accurate
- switch is more efficient than if else , because viewing disassembly finds the use of register-saving values to directly compare and then jump, and if else Each time you need the value of the op-expression to jump.
Const:
Const is a constant variable in C language cannot be left value
Const Constants in C + + must initialize symbols as local plus extern variable Global
The constant name is replaced with the initial value of the constant during compilation
The compiler must ensure that the amount of the Const modifier cannot be modified directly or indirectly (attempting to assign a constant address to a normal pointer)
If the initial value is a variable then degenerate into a constant variable
Const & Reference constants (addressable constants and non-addressable constants)
Const to the right without any pointers to the type, the reference does not participate in the type
volatile :
make a variable not be cached in a multithreaded program Guaranteed Visibility of the data no guarantee of atomicity
1. prevent the compiler from ordering optimization of assembly instructions
- compiler tuning volatile for order of instruction
- when the program runs CPU Tuning of the order of instructions barrier()
2. preventing copy values of register storage variables
struct and class differences:
variable functions can be defined in both 1.strcut and class to achieve polymorphic inheritance
2.struct more inclined to define data types,class is biased towards defining objects and methods
3.class inherits default private,struct inherits default public
4.class can use template,struct no
for an empty struct and class to distinguish between different structures (objects), assign at least one byte to store him, and pay attention to memory alignment.
The method of judging the small end of big-endian:
- Judging by the Union
- printf judgment
- Fetch address strong turn after dereference
malloc,realloc,calloc
malloc requests a piece of memory from the heap ( an anonymous mapping is called over the mmap threshold).
Calloc can be initialized after allocation.
ReAlloc expansion to the new size, problems that may occur:1. function is prone to ambiguity, causing memory leaks 2.realloc may move locations, andobjects inC + + may cause memory leaks by referencing external resources.
Summary of key keywords in C language