当前位置:网站首页>*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
边栏推荐
- 密西根大学张阳教授受聘中国上海交通大学客座教授(图)
- Quality blog——
- Usage of requests module
- Redis batch startup and shutdown script
- PHP wechat red packet grabbing algorithm
- 技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估
- Huawei switch console password reset, device initialization, default password
- Go language foundation ----- 09 ----- exception handling (error, panic, recover)
- HDMI2.1与HDMI2.0的区别以及转换PD信号。
- register关键字
猜你喜欢

Redis batch startup and shutdown script

PAT甲级 1032 Sharing

Go language foundation ----- 10 ----- string related operations (operation function, string conversion)

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

An article for you to understand - Manchester code

Technology dry goods | luxe model for the migration of mindspore NLP model -- reading comprehension task
![[step on the pit series] MySQL failed to modify the root password](/img/d0/f975baf18bac506208abff3713ac03.png)
[step on the pit series] MySQL failed to modify the root password

Harmonyos third training notes

技术干货|利用昇思MindSpore复现ICCV2021 Best Paper Swin Transformer

Project experience sharing: realize an IR Fusion optimization pass of Shengsi mindspire layer
随机推荐
【MySQL 11】怎么解决MySQL 8.0.18 大小写敏感问题
Pat class a 1030 travel plan
Static keyword
PDO and SDO concepts
[MySQL 12] MySQL 8.0.18 reinitialization
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition
截图工具Snipaste
输入三次猜一个数字
register关键字
技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
Traversal in Lucene
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
Go language foundation ----- 02 ----- basic data types and operators
What is a data type? What is the use of data types?
Client server model
什麼是定義?什麼是聲明?它們有何區別?
Iterm2 setting