当前位置:网站首页>*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
边栏推荐
- 项目经验分享:基于昇思MindSpore,使用DFCNN和CTC损失函数的声学模型实现
- Analysis of the eighth Blue Bridge Cup single chip microcomputer provincial competition
- Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
- PHP wechat red packet grabbing algorithm
- Harmonyos third training notes
- 技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
- 技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
- Worldview satellite remote sensing image data / meter resolution remote sensing image
- Register keyword
- Huawei switch: configure Telnet, SSH and web access
猜你喜欢
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
Iterm2 setting
Screenshot tool snipaste
技术干货|昇思MindSpore创新模型EPP-MVSNet-高精高效的三维重建
PAT甲级 1029 Median
技术干货|昇思MindSpore算子并行+异构并行,使能32卡训练2420亿参数模型
Lucene hnsw merge optimization
【LeetCode】4. Best Time to Buy and Sell Stock·股票买卖最佳时机
Go language foundation ----- 07 ----- method
OSPF experiment
随机推荐
Lucene merge document order
华为交换机:配置telnet和ssh、web访问
Project experience sharing: realize an IR Fusion optimization pass of Shengsi mindspire layer
Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task
Go language foundation ----- 05 ----- structure
register关键字
An article for you to understand - Manchester code
Go language foundation ----- 13 ----- file
Robots protocol
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Shengsi mindspire is upgraded again, the ultimate innovation of deep scientific computing
static关键字
【LeetCode】3. Merge Two Sorted Lists·合并两个有序链表
【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
OSPF protocol summary
华为交换机配置ssh登录远程管理交换机
基于RNA的新型癌症疗法介绍
Structure of golang
【MindSpore论文精讲】AAAI长尾问题中训练技巧的总结
技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估