The second sword of c language is the first introduction to pointers (preliminary understanding and analysis of pointers)

The second sword of c language is the first introduction to pointers (preliminary understanding and analysis of pointers)

1. Pointer (official definition)

Pointer is an important concept and its characteristics in C language , and it is also a difficult part to master C language . The pointer is also the memory address . The pointer variable is a variable used to store the memory address. Under the same CPU architecture, the length of the storage unit occupied by different types of pointer variables is the same, and the variable storing data is different due to the type of data. The length of storage space occupied is also different. With the pointer, not only the data itself, but also the address of the variable storing the data can be operated.

1.1 Self-understanding

From the official definition, it is not difficult for us to know that a pointer is an address in C language, and a pointer is also a variable, so it has so many attributes. What exactly is it? Let’s take a look at its address attribute first.

insert image description here

We can understand from the above picture that the pointer of the computer is actually the address in our life.

In reality, we can accurately find a person, a building, etc. through an address, while in a computer, we can use pointers to quickly find the data stored in the computer.

After understanding the address of the pointer, what does it mean that the pointer is also a variable? Let's use a bunch of code to understand

1.2 pointer variable

insert image description here

We created a variable a=10; but printed the variable of a as 20;

Why are two irrelevant variables related at a certain moment? Before that, let’s talk about a plot of a very popular TV series recently.

When Gao Qiqiang wanted to kill someone, he would never do it himself, but would say: "Lao Mo, I want to eat fish." Some people may be troubled by this, because it's not right. Let's say it again: "Gao Qiqiang (programmer) said, Lao Mo (*pa), I want to eat fish (change the value of a to 20).

See this moment. Do you understand? a is a variable, I created a *pa variable to store the address of a, and found the address of a using *pa to change the variable of a. So the value of a is changed.

*pa finds the address of a and changes the variable of a. So the value of a is changed.

The above is my initial understanding of pointers. If there are any deficiencies, please criticize and correct me. As an apprentice who is just learning C language, I will maintain a humble and studious attitude. Thank you for all the big brothers who criticized and corrected me. One thanks!

Guess you like

Origin blog.csdn.net/nanmiao666/article/details/130139574