当前位置:网站首页>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;
}
边栏推荐
- Principle of distribution: understanding the gossip protocol
- Shardingsphere proxy 4.1 sub database and sub table
- String longest common prefix
- How do wechat applets make their own programs? How to make small programs on wechat?
- ShardingSphere-Proxy 4.1 分庫分錶
- Exception: gradle task assemblydebug failed with exit code 1
- Requirements and precautions for applying for multi domain SSL certificate
- How to make a self-service order wechat applet? How to do the wechat order applet? visual editing
- CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
- (forwarding articles) after skipping multiple pages, shuttle returns to the first page and passes parameters
猜你喜欢

Flask博客实战 - 实现侧边栏文章归档及标签

Tiktok brand goes to sea: both exposure and transformation are required. What are the skills of information flow advertising?

我希望按照我的思路盡可能將canvas基礎講明白

我希望按照我的思路尽可能将canvas基础讲明白

Ruiji takeout project (II)

Unique Wulin, architecture selection manual (including PDF)

CyCa 2022 children's physical etiquette primary teacher class Shenzhen headquarters station successfully concluded

How do wechat sell small commodity programs do? How to open wechat apps to sell things?

Redis(一)原理与基本使用

MongoDB的原理、基本使用、集群和分片集群
随机推荐
The problem of automatic page refresh after the flyer WebView pops up the soft keyboard
String implementation strstr()
Flutter replaces the default icon of Gaud positioning
Pytorch_ Geometric (pyg) uses dataloader to report an error runtimeerror: sizes of tenants must match except in dimension 0
View. post VS Handler. Differences and usage scenarios of post
独步武林,架构选型手册(包含 PDF)
【论文阅读|深度】Role-based network embedding via structural features reconstruction with degree-regularized
ShardingSphere-Proxy 4.1 分库分表
Set the location permission in the shutter to "always allow"
manhattan_ Slam environment configuration
Floating window --- create an activity floating window (can be dragged)
Rxjs TakeUntil 操作符的学习笔记
字符串 实现 strStr()
Minio基本使用与原理
申请多域名SSL证书的要求及注意事项
I hope to explain the basics of canvas as clearly as possible according to my ideas
How to install SSL certificates in Microsoft Exchange 2010
Shuttle JSON, list, map inter transfer
Jetpack compose layout (III) - custom layout
Flask博客实战 - 实现侧边栏文章归档及标签