当前位置:网站首页>Understanding of C pointer

Understanding of C pointer

2022-06-22 05:52:00 Silly boy: CPU

C Understanding of pointer

The pointer ( An object in a programming language ): The pointer is the memory address , Pointer variables are variables used to store memory addresses , In the same CPU Under Framework , Different types of pointer variables occupy the same length of storage unit , Depending on the type of data stored in the variable , The amount of storage space used is also different .

int a=3; // Common variable definitions 

Defining variables a When , The computer will give a Open up a memory space , This memory space is a The address of . For example 0xA0. What's in memory is 3 This value .
 Insert picture description here

int *p;// Define a pointer 
p = &a;// Pointer assignment 

When defining pointers , The computer will also give p Open up a memory space , For example, the memory address is 0XB0.p=&a It means that you will a To the pointer , Stored in the memory of the pointer . That is to say Put a memory address in the memory space , Not a number or a constant .
 Insert picture description here

*p;// Indicates to fetch the pointer address (p Address in memory ) Value pointed to (a Value in memory ).*p=3
p;// ordinary p The pointer ,p Address stored in ( The content is 0XA0), Unlike other variables that hold values or constants 
&p;// Express p The address of ( Computer assigned address ), The content is 0XB0
*p;// Indicates the contents of the address pointed to by the pointer , The content is 3

 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[Silly boy: CPU]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220533039224.html