当前位置:网站首页>The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
2022-06-13 05:54:00 【Python's path to becoming a God】
Auto increment and auto decrement operator yes Composite operators A simpler way of writing
Variable a Add yourself 1 Can be expressed as :
a=a+1;
Composite operators notation
a+=1;
Self - increment operator notation
a++;
++a;
Correspondingly, there are Self - subtracting operator notation
a--;
--a
After the completion of self increase and self decrease , Meeting Replace old value with new value Save in current Variable in .
The result of self increasing and self decreasing must have a variable to receive , Therefore, self increase and self decrease can only be applied to Variable , Cannot be for numbers or expressions .
Pre auto increment ( Self reduction ) Self increasing after and ( Self reduction ) The difference between :
An example : Output i The value after self increment and are respectively i++ and ++i The assignment of j Value , Analyze the difference between the two kinds of autoincrement
#include <stdio.h>
int main() {
int i = 5, j;
j = i++;
printf("i=%d,j=%d\n", i, j);
i = 5;
j = ++i;
printf("i=%d,j=%d\n", i, j);
return 0;
}
According to the observation results i All values change to 6, however j But they are assigned to 5 and 6, That is to say, the difference between pre auto increment and post auto increment is that the value is assigned after auto increment , The other one assigns values first and then increases automatically .
Mnemonics :
【 According to the assignment character ‘=’ After Variable i In the form of Judge i Whether the value before or after auto increment is assigned to j】
if 【++i】, Then put ++i As a whole , Put the self increasing i value (++i) Assign to j( Self increment and then assignment );
if 【i】, First put i Value is assigned to j, let i Self increasing ( First assign value and then auto increment ).
( Self subtraction as above )
边栏推荐
- Missing tag identification in cots RFID systems: bringing the gap between theory and Practice
- SPI primary key generation strategy for shardingsphere JDBC
- How MySQL optimizes the use of joint index ABC
- Calculate the number of days between two times (supports cross month and cross year)
- 软件测试——接口常见问题汇总
- Leetcode- reverse string - simple
- How slow is the application system on tongweb? How dead is it?
- 9. Errorstartevent and errorboundaryevent of error events
- Four shardingsphere JDBC sharding strategies
- 16 the usertask of a flowable task includes task assignment, multi person countersignature, and dynamic forms
猜你喜欢
MongoDB 多字段聚合Group by
Quartz basic use
SPI primary key generation strategy for shardingsphere JDBC
Sentinel series integrates Nacos and realizes dynamic flow control
The reason why the process cannot be shut down after a spark job is executed and the solution
Getclassloader() returns null, getclassloader() gets null
Building a stand-alone version of Nacos series
Ffmpeg download suffix is Video files for m3u8
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
AUTOSAR实战教程pdf版
随机推荐
顶部下滑沉浸式dialog
Leetcode- reverse vowels in string - simple
Concurrent programming -- what is threading?
Pychart professional edition's solution to SQL script error reporting
Getclassloader() returns null, getclassloader() gets null
The 13th week of the second semester of sophomore year
powershell优化之一:提示符美化
AUTOSAR实战教程pdf版
Integer tips
Exception after repeated application redeployment on tongweb: application instance has been stopped already or outofmemoryerror:metaspace
One of PowerShell optimizations: prompt beautification
Pychart encountered time zone problem when connecting to MySQL timezone
Leetcode- longest continuous increasing sequence - simple
中断处理过程
2021.9.29 learning log MIME type
[automated test] cypress manual
Leetcode- complement of numbers - simple
10 signalstartevent and signalcatchingevent of flowable signal events
Leetcode- intersection of two arrays ii- simple
Power simple of leetcode-3