The relationship between pointers and memory in C language

1. Memory and bytes

A memory unit == a byte == an address
The number of bytes of the int type in the integer type int type is 4, and one byte represents eight bit bits, and one binary bit has 32 bit bits
So it can be expressed as: a byte == 8 bits == one-eighth of a 32-digit binary digit 

For example: int a = 10;

The meaning expressed by this expression: apply for 4 bytes to the memory to store the number 10 

——It is to divide the 32 binary digits of 10 into four parts, one part is eight bits 

The four copies have different addresses, and we use the address with the lowest address bit as the first address .

And when & is used as an address symbol, &a means to take the first address of the address stored in the memory by a, which has the same meaning as the array name in the array. The first address can represent the spatial position of a in the memory .

2. Memory and pointers

int * p = & a

First, we want to store &a in a variable p, and p is therefore called a bit pointer variable

And the type of p is int *

And * means that p is a pointer variable - a proof

int represents a type of a in the address &a pointed to by p  

int * also indicates the type of the pointer variable p

*p represents a kind of pointing, through the address stored in p, find the space pointed to by the address *p is the variable a

p is the address where the content is stored and is an address number

As shown in the figure, what is stored in the pointer variable p is actually &a, which is an address number, and this address number guides the pointer variable p to point to the space represented by this address number

It is equivalent to the pointer variable p (*p) is the variable a 

So when the pointer variable p (*p) changes, the variable a will also change accordingly

For example: *p = 0 is equivalent to a = 0;

Guess you like

Origin blog.csdn.net/2301_76445610/article/details/132167488