当前位置:网站首页>Basic knowledge of pointer
Basic knowledge of pointer
2022-06-25 14:50:00 【䨁 逦】
Restate the pointer here
The concept of pointer
* Each variable is stored in a memory address ( In bytes ) In the first few bytes ,
* The pointer , Also known as pointer variables , The size is 4 Bytes ( or 8 Bytes ) The variable of , Its content
Represents a memory address .
* Through the pointer , It can read and write the memory area of the pointer .
* If you think of every byte of memory as a room number , Then the memory address is equivalent to the room number , And the pointer
The room number is stored in the .
~ Definition of pointer
Type name * Pointer variable name
int * p;
double * pc;( Type name )// data type
char *pf;
~ Contents of pointer
int *p =(int *) 40000;
p Pointing to the address 40000, Address p It's the address 40000;
*p It means address 40000 The contents of the first few bytes
Access the memory space pointed to through the pointer
~ Pointer definition summary
T* p//T It can be any type of name , such as int double char
p The type of T*
*p The type of : T
Through the expression *p , Can read and write slave address p At the beginning sizeof(T) Bytes
*p Equivalent storage address p One of the T Variable of type
* Indirect reference operators
~ Pointer usage
char ch1 ='A'
char *pc=&ch1// bring pc Point to ch1
& : Fetch address operator
&x: Variable x The address of ( Point to x The pointer to )
For types of T The variable of x,&x Said variable x The address of ( Point to x The pointer to )&x The type is T*
With the pointer , You have the means to freely access memory space
You don't need to pass variables , You can directly operate on the memory . Through the pointer , The memory area that the program can access is
Not limited to the data area occupied by variables .
~ Mutual assignment of pointers
Different types of pointers , If you don't cast , Cannot assign values to each other directly .
//int &pn, char *pc,char c=ox65;
pn=pc;// Type mismatch , Compilation error ,( Pointers of the same type can be assigned to each other )
pn=&c;// Type mismatch , Compile error ,
pn=(int *)&c;
int n=*pn;//n Value uncertainty ;( Different types of pointers , Must be cast to assign values to each other )
~ The operation of the pointer
(1) Two pointer variables of the same type , You can compare the size
Address p1< Address p2, Equivalent p1<p2 It's worth it .
Address p1= Address p2, Equivalent p1==p2 It's worth it
Address p1> Address p2, Equivalent p1>p2 It's worth it
(2) Two pointer variables of the same type , You can add and subtract
Two T* Pointer to type p1 and p2
p1-p2=( Address p1- Address p2)/sizeof(T)
such as int *p1,*p2;
p1=1000,p2=600;
p1-p2=(1000-600)/sizeof(int)=(1000-600)/4=100;
(3) The result of adding or subtracting an integer from a pointer variable is a pointer
p:T* A pointer to a type
n: Variable or constant of integer type
p+n:T* Pointer to type , Pointing to the address
Address p+n*sizeof(T)
(4) Pointer variables can be self incremented , Self reduction
T* Pointer to type p Pointing to the address n
p++,++p:p Point to n+ sizeof(T)
p--,--p:p Point to n-sizeof(T)
(5) Pointers can use subscript operators "[]" Carry out operations
p It's a T* Pointer to type
n Is a variable or constant of integer type
p[n] Equivalent to *(p+n);
边栏推荐
- Kubernetes understands kubectl/ debugging
- Using Sphinx to automatically generate API documents from py source files
- QQ情话糖果情话内容获取并保存
- Real variable instance
- QQ love talk candy love talk content acquisition and storage
- Report on Hezhou air32f103cbt6 development board
- Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
- Automatic correlation between QT signal and slot
- 分享自己平时使用的socket多客户端通信的代码技术点和软件使用
- 2020-03-20
猜你喜欢

Open a restaurant

JS recursion and while

How to make GIF animation online? Try this GIF online production tool

Renix perf: detailed explanation of IP network performance test tools and test case parameters

Page 112 machine learning - review of fundamentals of mathematics pptx

Clinical chemistry | zhangjianzhong / Xu Jian develop single cell precision diagnosis and treatment technology for Helicobacter pylori

Kubernetes 理解kubectl/调试

Flexible layout (display:flex;) Attribute details

15 -- 最接近原点的 K 个点

定位position(5种方式)
随机推荐
QQ love talk candy love talk content acquisition and storage
移除区间(贪心)
Clipboard tutorial
Common classes in QT
Remove interval (greedy)
How to make GIF animation online? Try this GIF online production tool
How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
Biscuit distribution
Ideal L9 in the eyes of the post-90s: the simplest product philosophy, creating the most popular products
QQ情话糖果情话内容获取并保存
New good friend Pinia, leading the new era of state management
15 -- 最接近原点的 K 个点
JGG | 河北大学杜会龙组综述植物泛基因组学研究
Summary of common functions in Oracle Database
【深度学习】多任务学习 多个数据集 数据集漏标
The best time to buy and sell stocks
Disable scrolling in the iPhone web app- Disable scrolling in an iPhone web application?
What is the difference between escape, encodeuri and encodeuricomponent?
JS recursion and while
QT database connection deletion