2. What is a pointer?
It's not easy to understand! Many of us who are new to pointer should feel this way. I often think about it. Why? In fact, there are pointers everywhere in life. We also use it everywhere. With it, our life is more convenient. No pointer makes life inconvenient. Believe it? See the following example.
This is an example of life: for example, if you want me to lend you a book, I went to your dormitory, but you are not in the dormitory, so I put the book on your shelf on the 2nd floor and 3rd, and put a piece of paper on your desk. The paper says: The book you want is on the shelf on the 3rd floor, 2nd. When you come back, you will see this note. You will know where I borrowed your book and put it. You can think about the function of this paper. It is not a book, and there is no book on it. So how do you know where the book is located? Because the book is written on the paper! In fact, this paper is a pointer. The content above is not the book itself, but the address of the book. You found the book I lent you through the pointer.
So what are the pointers in C and C ++? Continue with me. Let's see a statement that declares an integer pointer variable as follows:
Int * PI;
Pi is a pointer, of course we know, but in this case, you think pi must be something special. In fact, it is only a variable. There is no substantive difference from the variable mentioned in the previous article. Do not believe it.
Memory Address → 6 7 8 9 10 11 12 13 14
--------------------------------------------------------------
... | 30 | 'T' | ......
--------------------------------------------------------------
Variable | → I branch | → A branch | → PI branch |