Before the theory is too much, the following is a combination of code and
1, sizeof () is a standalone operator, not a function, you can let us know any variable byte number, can incidentally learn struct,union, memory alignment
Memory alignment: For machine instructions to quickly point to the address value, the compiler internal memory is actually aligned, how to understand, with a struct as an example
Let's talk about each variable type memory size
So the struct is theoretically: 1+2+4+4+4+8+8 = 31, but actually
The actual size is 32 (1+2+1+4) + (4+4) +8+8
And then swap the int and the short position.
The actual size is 40 (1+3) +4+ (+4+) (4+4) +8+8
This way, there will be different changes in the number of system bits and compilers.
Union more unexpected
G
All of its variables share an address, so the memory size is the largest variable, only one variable value can be saved at a time, overwriting
2, the following two debugging skills
assembly or hardware embedded development, inconvenient code changes frequently, you can use
1), Pre-treatment method
#define DEBUG
#if DEBUG
/* Process Debugging */
#endif
2), code switch, add a bool parameter, its value can be entered from the function parameter
3. Function pointers
void Func () {
..................;
} This is a function declaration
void (*p) (), function pointer, pointer to a function that has no parameter return value of void type, which is the basic
There are many more complex sensations that will not be used, such as a double (* (* (*P) ()) [x]) (), p is a pointer to a function, and there is no parameter, and points to a pointer with 10 pointers to the array of function pointers-business code is seldom used, so there is basically no way to maintain it. At most, the person himself writes the internal use of the library, should not be used as an interface
NOTE: Int (* (*p ()) [10]) (); Is a function, p is a function that returns a pointer to an array containing 10 function pointers
C + + programming Thought (c)--c++, focus sizeof and memory alignment