当前位置:网站首页>*p++、*++p、++*p、(*p)++
*p++、*++p、++*p、(*p)++
2022-07-03 07:49:00 【Seven demons 71】
Arrangement c I found several interesting things when I was using the language pointer , Go directly to the code to explain .
Background conditions
GCC edition 7.4.0
i++: First use i, Re increment
++i: Increase first , Reuse i
Priority table :
Operators of the same priority , The operation order is determined by the combination direction .
*p++
#include <stdlib.h>
int buf[]={
1,3,5};
int main()
{
int *p = buf;
printf("%d\r\n",*p++);
printf("%d",*p);
return(0);
}
result :

analysis
According to the priority table * and ++ At the same priority . Then look at the direction , From right to left . therefore p++, then *.
Look again i++ The nature of , First use i, Re increment . It was printed first when printing for the first time *p yes buf[0]=1, After printing , Re execution *(p++), here p Point to buf[1]. So the second print out is 3.
*++p
#include <stdlib.h>
int buf[]={
1,3,5};
int main()
{
int *p = buf;
printf("%d\r\n",*++p);
printf("%d",*p);
return(0);
}
result :
analysis
This is very simple The previous question is the same as the previous one . First ++p then *.
++p It is to calculate first and then execute . So both point to buf[1]=3
++*p
#include <stdlib.h>
int buf[]={
1,3,5};
int main()
{
int *p= buf;
printf("%d\r\n",++*p);
printf("%d",*p);
return(0);
}
result :
analysis
First *p, then ++, because *p=1, then ++(*p), It is to calculate first and then execute , So the result is 2.
(*p)++
#include <stdlib.h>
int buf[]={
1,3,5};
int main()
{
int *p= buf;
printf("%d\r\n",(*p)++);
printf("%d",*p);
return(0);
}
result :
analysis
First in parentheses *p=1, And then again ++.
The first printing is incremental because it is executed first , So the result is 1
The second printing is over because of the increment, and then 2
边栏推荐
- Huawei s5700 switch initialization and configuration Telnet, SSH user methods
- Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
- Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
- What to do after the browser enters the URL
- 什麼是定義?什麼是聲明?它們有何區別?
- 华为交换机Console密码重置、设备初始化、默认密码
- Redis查看客户端连接
- Go language foundation ----- 09 ----- exception handling (error, panic, recover)
- LwIP learning socket (application)
- C2-关于VCF文件合并的几种方法
猜你喜欢

Pat grade a 1029 median

【MySQL 12】MySQL 8.0.18 重新初始化

Go language foundation ----- 01 ----- go language features

在浏览器输入url后执行什么

Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task

Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition

密西根大学张阳教授受聘中国上海交通大学客座教授(图)

Go language foundation ----- 07 ----- method
![[mindspire paper presentation] summary of training skills in AAAI long tail problem](/img/34/9c9ec1b94edeecd4a3e7f20fdd8356.png)
[mindspire paper presentation] summary of training skills in AAAI long tail problem

Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
随机推荐
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
什么是定义?什么是声明?它们有何区别?
PAT甲级 1028 List Sorting
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
How does yarn link help developers debug NPM packages?
Register keyword
Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
[at] abc 258G - Triangle 三元组可达-暴力
密西根大学张阳教授受聘中国上海交通大学客座教授(图)
优质博客——
【LeetCode】2. Valid Parentheses·有效的括号
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
Analysis of the problems of the 10th Blue Bridge Cup single chip microcomputer provincial competition
opensips与对方tls sip trunk对接注意事项
go语言-循环语句
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
OSPF protocol summary
Redis view client connection
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
Go language foundation ----- 15 ----- reflection