当前位置:网站首页>The real difference between i++ and ++i
The real difference between i++ and ++i
2022-06-25 10:14:00 【QQ851301776】
Created by QQ:851301776, mailbox :[email protected], Welcome to technical exchange , This blog is mainly my own learning experience , Just to make a little progress every day !
Personal motto :
1. No one was born , As long as it is thick, it will happen .
2. You can have a low degree , You can skip school , But you have to learn
One 、i++ and ++i Essential difference

The core difference is :i++ There are reasons for intermediate preservation .
Two 、 Test drill
#include <stdio.h>
int add1()
{
int i=0;
#if 1
printf("add1 = %d\n", (i++ + i++));
printf("i =%d\n", i);
i =0 ;
printf("add2 = %d\n", (i++ + ++i));
printf("i =%d\n", i);
#endif
i =0;
printf("add3 = %d\n", (++i + ++i));
printf("i=%d\n", i);
return 0;
}
int main(void)
{
int i = add1();
printf("main i= %d\n", (i++));
return 0;
}
[email protected]:/mnt/hgfs/project/visual_gateway/software/src_intra_20220618/test/v1/test/xx3/test$ ./a.out
add1 = 1
i =2
add2 = 2
i =2
add3 = 4
i=2
main i= 0
analysis :
Combined with the first part : give an example i++ Return to temp, ++i return i, Just to distinguish
(1)printf("add1 = %d\n", (i++ + i++));
![]()
- First, execute the... On the left i++, here i=0, The result returned temp1 = 0, here i The value of is 1.
- Next, execute the... On the right i++, here i=1, The result returned temp2=1, here i The value of is 2.
- Finally, execute the middle addition , by (temp1 + temp2)
(2)printf("add2 = %d\n", (i++ + ++i));
![]()
- First, execute the... On the left i++, here i=0, The result returned is temp=0, here i The value of is 1.
- Next, execute the... On the right ++i, here i=1, The result returned is i =2, here i The value of is 2.
- Finally, execute the middle addition , by (temp + i)
(3)printf("add3 = %d\n", (++i + ++i));
![]()
- First, execute the... On the left ++i, here i=0, The result returned is i=1, here i The value of is 1.
- Next, execute the... On the right ++1, here i=1, The result returned is i=2, here i The value of is 2.
- Both left and right return i, At this time i All equal to 2
- Finally, execute the middle addition , by (i+i)= 4( The main thing that needs to be done here is : First time back i It was equal to 1, Now it has become 2)
(4)printf("main i= %d\n", (i++));
The previous return value i=0;
here , The result is also 0.
3、 ... and 、 Other tests
1.demo
#include <stdio.h>
int add1()
{
int i=0;
printf("add1 = %d\n", (i++ + i++)); // Print equals 1, i=2
printf("i =%d\n", i);
printf("add2 = %d\n", (i++ + ++i)); // Print equals 6, i=4
printf("i =%d\n", i);
printf("add3 = %d\n", (++i + ++i)); // Print equals 12, i=6
printf("i=%d\n", i);
return 0;
}
int main(void)
{
int i = add1();
printf("main i= %d\n", (i++));
return 0;
}
边栏推荐
- [MySQL learning notes 22] index
- Grabcut image segmentation in opencv
- Learning notes of rxjs takeuntil operator
- The gradle configuration supports the upgrade of 64 bit architecture of Xiaomi, oppo, vivo and other app stores
- 我希望按照我的思路尽可能将canvas基础讲明白
- DDS learning notes of opendds
- Vscode attempted to write the procedure to a pipeline that does not exist
- Yolov5 changing the upper sampling mode
- String implementation strstr()
- The path of Architects
猜你喜欢

Methodchannel of flutter
![[buuctf.reverse] 117-120](/img/6c/8a90fff2bd46f1494a9bd9c77eeafc.png)
[buuctf.reverse] 117-120

manhattan_ Slam environment configuration

Can two Mitsubishi PLC adopt bcnettcp protocol to realize wireless communication of network interface?

Download the arm64 package of Debian on X86 computer

Encoding format for x86

The left sliding menu +menu item icon is grayed out

Learning notes of rxjs takeuntil operator

How much does a wechat applet cost? Wechat applet development and production costs? Come and have a look

Redis(二)分布式锁与Redis集群搭建
随机推荐
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
Experience in writing C
Set the location permission in the shutter to "always allow"
Force buckle -104 Maximum depth of binary tree
Flask博客实战 - 实现侧边栏最新文章及搜索
The path of Architects
2台三菱PLC走BCNetTCP协议,能否实现网口无线通讯?
Rxjs TakeUntil 操作符的学习笔记
Flutter Gaode map privacy compliance error
Deep understanding of JVM - JVM memory model
Floating window --- create an activity floating window (can be dragged)
Flutter dialog: cupertinoalertdialog
How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
Difference between malloc and calloc
Houdini图文笔记:Could not create OpenCL device of type (HOUDINI_OCL_DEVICETYPE)问题的解决
Yolov5更换上采样方式
The way that flutter makes the keyboard disappear (forwarding from the dependent window)
Oracle查询自带JDK版本
Use evo
js工具函数,自己封装一个节流函数