Pointer, uncover your cover (2)

Source: Internet
Author: User

 

Understand Variables

Let's take a look:

I use graphs to represent the values of five integers in a memory segment. Each box represents an integer, and the value in the box represents the actual value of the integer, the value at the top of each box indicates the address of this integer in the memory. We can think of it as a memory representation. This is really an image!

For a computer, as long as you tell it the address of this integer, it can easily get the actual value of the address pair. However, it is very difficult for humans to remember this address, don't look at the above. I use 1001,1002 and other values for representation. You may not think it is hard to remember. In reality, the computer uses hexadecimal data to record the memory address, it's basically huge, for example, 82364a7f97612. Are you looking at it as big? How do we remember the memory data in the computer? Let's take a look:

 

Is this image similar to the secondary image above? Yes, we just replaced the above 1001,1002 with A, B, C, D and so on.

If we remember the complicated, long hexadecimal data like computers, it would be a waste of humans, so humans have invented another way to remember memory, it is the location where the memory is accessed by name rather than address. The A, B, C, D and so on in the memory are the names of the memory, and each name corresponds to a value.

What is this name? Is the variable declared in our program. So we understand that this is the essence of the variable. What is the variable? It is to identify a memory address, that is, to record a piece of memory data. In the program, we obtain the memory value by accessing the variable.

What is the relationship between variables and addresses? A variable in the compiler can correspond to only one unique memory address at a time, but one memory address can correspond to multiple different variables. That is to say, a memory address can be represented by multiple variables, but one variable can only correspond to one memory address.

Variables are designed to help humans remember memory locations, but for computers, they do not recognize variables. The relationship between variables and memory locations is not stored by hardware, but implemented by the compiler. Humans declare a variable first, and assign the value to the variable. The Compiler applies for a piece of memory and stores the data in the memory, and then maps the address of the memory to the variable. Similarly, the human gets the corresponding data by converting the variable into an address through the compiler. In a word, humans use variables, the compiler converts variables into addresses, and the hardware uses addresses to access memory locations. Eventually, the computer accesses the memory through the address. Only humans access the memory through variables, and the compiler is a bridge between them.

 

You must understand the Data Type

Why is data type required? Of course, my reasons are that pointers and data types are inseparable. I cannot talk about pointers to you on the premise that you do not understand the data types, I can only talk about you, but I am sweating.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.