Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language pointer
C language pointer
The basic unit of memory is the storage unit.

A storage unit occupies 8 bits, namely 1 byte.

Each memory cell has a corresponding address.

The so-called address is simply a number, which can be understood as everyone's ID number.

The memory of pointer variable p and variable a is created on the stack.

Both variables occupy 4 bytes, that is, 4 consecutive memory locations.

& ampP is the first address of pointer P, that is, the number (address) of the first storage unit.

& ampA is the first address of variable A, that is, the number (address) of the first storage unit.

p = & ampa; It means that the first address of variable A is assigned to variable P, or it can be said that P keeps the first address of variable A..

Now P and&; A is the same address, so the contents stored in the same address are naturally the same.

Use *p or a to get the content stored in this address.

So the contents of *p and A are the same.

There is no address allocation, only memory allocation and storage unit allocation.

Address, the full name of which is physical address or logical address, consists of segment base address and offset. The physical address is synthesized by the address accumulator, that is to say, each storage unit has a corresponding physical address, which is designated, not assigned, only addressed.

The so-called addressing refers to the first address of your allocated memory, which depends on what your memory was created on. (There are three ways to create memory in C language) Which segment of memory is it? To give you the corresponding first address, that is, this memory, which is decided by the compiler, not you.

If you are interested, you can learn the principle and compilation of microcomputer, which is more complicated, involving hardware and assembly, and counting electricity. It will give you a better understanding of these things.

On your present basis, just remember what I wrote above and distinguish the relationship between memory, storage unit and address. Leave the rest to the compiler. You don't need to know much. Learn slowly. You can't be fat. This is a process.