当前位置:网站首页>*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
边栏推荐
- Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
- Epoll related references
- 技术干货|昇思MindSpore NLP模型迁移之Roberta ——情感分析任务
- 华为交换机配置ssh登录远程管理交换机
- 技术干货|昇思MindSpore NLP模型迁移之Bert模型—文本匹配任务(二):训练和评估
- PAT甲级 1031 Hello World for U
- Pat grade a 1029 median
- Pat grade a 1027 colors in Mars
- OSPF experiment
- Huawei switch basic configuration (telnet/ssh login)
猜你喜欢

The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.

Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)

Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction

PAT甲级 1030 Travel Plan

Go language foundation ----- 02 ----- basic data types and operators
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization

vcs import src < ros2. Repos failed

截图工具Snipaste

研究显示乳腺癌细胞更容易在患者睡觉时进入血液

Partage de l'expérience du projet: mise en œuvre d'un pass optimisé pour la fusion IR de la couche mindstore
随机推荐
Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
HarmonyOS第三次培训笔记
华为S5700交换机初始化和配置telnet,ssh用户方法
Technical dry goods Shengsi mindspire elementary course online: from basic concepts to practical operation, 1 hour to start!
技术干货|百行代码写BERT,昇思MindSpore能力大赏
opensips与对方tls sip trunk对接注意事项
PHP微信抢红包的算法
Screenshot tool snipaste
【LeetCode】2. Valid parentheses · valid parentheses
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
[at] abc 258G - Triangle 三元組可達-暴力
基于RNA的新型癌症疗法介绍
截图工具Snipaste
技术干货|昇思MindSpore可变序列长度的动态Transformer已发布!
Technical dry goods Shengsi mindspire innovation model EPP mvsnet high-precision and efficient 3D reconstruction
[step on the pit series] MySQL failed to modify the root password
华为交换机:配置telnet和ssh、web访问
An article for you to understand - Manchester code
Redis view client connection
GoLang之结构体