Chapter 4 Pointer pointer (advanced) and Pointer (advanced)
Chapter 4 pointer (advanced)
So this course is to learn how to implement pointer and How to Use pointer.
We already know how to declare a pointer in the pseudo-code.
Integer myNum
RefToInteger myNumPtr
In C ++
Int myNum;
Int * myNumPtr;
Suppose X is any type.
Pseudo code: declare a pointer named ptr using refToX ptr
C ++: declare a pointer named ptr using X * ptr
It is worth noting that * this symbol is easy to mix.
Int myNum; // This declares an integer
Int * myNumPtr; // This declares a pointer to an integer
MyNum = 7;
MyNumPtr = & myNum; // This puts the address of myNum
Into the variable myNumPtr
This will happen in the memory.
Address Content
4683953 7 myNum
4683954 myNum
4683955 myNum
4683956 myNum
4683957 4683953 myNumPtr
4683958 myNumPtr
4683959 myNumPtr
4683960 myNumPtr
At this time, we declare an integer myNum as 7. At this time, we need a certain amount of memory space to store this integer. We all know that the integer size is 4.
However, the size of a pointer is also 4. Therefore, four Memory Spaces are allocated to the pointer during the Declaration. This memory space is the location pointed to by the pointer.
In the above example, the value stored by myNumPtr is the address, AKA, 4683953 of the value it points.
PS what we need to know is that the current computer memory is very large, so in the real situation, a pointer is adjacent to the value referred by this pointer is extremely rare.
This is very late, so write it here first. Continue tomorrow.