Recommended reading:
C ++ disassembly code analysis-function call
C ++ disassembly code analysis-loop structure
C ++ disassembly code analysis-stealing Functions
Go to the memory and run the Assembly command to check the C/C ++ pointer.
Two points:
1. P and * P in the compilation
2. Jin Ke Yu law on Pointer Initialization
Int * P;
P and * P, I believe many people have been confused here, and finally remember their differences in the rote memorization, but what is actually, I have not personally read them in the memory. Here, it will take you to the memory to see, to the Assembly to see the true colors of P and * P.
SimpleProgram:
1 # Include < Iostream >
2 Using Namespace STD;
3 Int Main ()
4 {< br> 5 int I = 1 ;< br> 6 int * P =& I;
7 }
First read assemblyCodeAnalysis:
(If you don't understand why the [ebp-4] [ebp-8] stores the first and second local variables of the function, you can read c ++ disassembly code analysis-function call first)
Many people have asked the pointer P to point to an address. Does the pointer P have its own address? The answer is yes. The above analysis shows that the address of P is 0012ff40, and the address stores the address of variable I. In addition to this method, there is also an output method to view P's own address. If int * (* q) = & P; then Q stores the P address, you can view the output by yourself.
Verify the following from the memory:
We have analyzed that the P address is 0012ff40. You can check it in the memory observer,
The last small verification, huh, looks directly at the variable Monitor (in fact, the simplest ):
Okay, you know them, huh, huh. When learning the C ++ pointer, many people are in the fog. After a while, the address will be worth a while. If the teacher says what it is, let's get a look at it. I am very curious about myself, and I like everything. At that time, I would like to open the memory to see if it is like this, but at that time I would not, I felt so bad. If you are the same as me, watch it. In fact, it is very useful to understand the pointer, especially when learning security-related things.
2. pointer Initialization
Let's just talk about the golden rule about using pointers: You must initialize a definite and appropriate address for the pointer before removing the reference operator (*) from the pointer application.
It is still a simple small program:
1 # Include < Iostream >
2 Using Namespace STD;
3 Void Main ()
4 {
5 Int I = 1 ;
6 Int * P;
7// Int * P = & I;
8 * P = 1 ;
9}
// There are two cases in total. One is to give the Pointer a definite and appropriate address, and then assign a value of 1. The other is none. assign a value of 1 directly.
View Assembly commands directly:
This section only describes the golden rule for pointer initialization. As for other initialization operations, there should be no more details.
Reference books: C ++ primer plus Stephen Prata translated by Sun Wei Qiang