This section will analyze the pointers in detail.
First, the pointer
The pointer is actually a variable, but what makes this variable unique is that the value he saved is an address.
int a = 4; int* p = &a;
The memory of this piece of code
As can be seen, p is essentially a variable, but this variable is special, his value is the address of a variable.
At this point, we can access the value saved by the address stored by the P variable via the * number, which can be a bit of a detour. To put it simply, that is, when *p does this, the reading is actually the value of a, which means that *p ==> 4.
Second, the value call and the address call
If you need to change the arguments inside the function body, you need to do so by using a pointer.
Consider a problem that uses a function to complete the two-number exchange. This is basically the function that we will write at the beginning of the C language.
int swap (int* A, int* b) {int c = *a; *a = *b; *b = C;}
The function does not change the value of the argument when it is called, only the value of the argument is used inside the function.
Three, constant pointer
We've discussed the Const keyword before, which combines the const keyword with the pointer. There are several important points to note:
const int* p; P variable, the content of P pointing is immutable int cosnt* p; Same as last time, no difference int* const p; P is immutable, the content of P points variable const int* const p; P is immutable, and the content of P is not variable.
For the combination of the memory const and the pointer, there is a formula, the left number right finger.
C-language leak check---hands