当前位置:网站首页>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 )
边栏推荐
- Vagrant virtual machine installation, disk expansion and LAN access tutorial
- Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio
- How slow is the application system on tongweb? How dead is it?
- Implementation of concurrent programming locking
- Leetcode longest harmonic subsequence simple
- Misunderstanding of tongweb due to ease of use
- 中断处理过程
- Top slide immersive dialog
- A simple recursion problem of linked list
- Hump naming and underlining
猜你喜欢

Sentinel series integrates Nacos and realizes dynamic flow control

One of PowerShell optimizations: prompt beautification

Byte buddy print execution time and method link tracking

Config server configuration center of Nacos series

OpenGL马赛克(八)

12 error end event and terminateendevent of end event

软件测试——接口常见问题汇总

Zero copy technology

Software testing - Summary of common interface problems

17 servicetask of flowable task
随机推荐
The reason why the process cannot be shut down after a spark job is executed and the solution
MySQL installation in Linux Environment
ffmpeg 下载后缀为.m3u8的视频文件
The SQL file of mysql8.0 was imported into version 5.5. There was a pit
Pychart professional edition's solution to SQL script error reporting
Leetcode guessing numbers game - simple
Leetcode- intersection of two arrays - simple
No assessment summary
Power of leetcode-4 - simple
19 calling subprocess (callactivity) of a flowable task
MongoDB 多字段聚合Group by
3. Postman easy to use
Leetcode- string addition - simple
10 signalstartevent and signalcatchingevent of flowable signal events
Concurrent programming -- source code analysis of thread pool
OpenGL Mosaic (8)
Leetcode- longest continuous increasing sequence - simple
20 flowable container (event sub process, things, sub process, pool and pool)
August 15, 2021 another week
Hump naming and underlining