当前位置:网站首页>Distinguish between i++ and ++i seconds

Distinguish between i++ and ++i seconds

2022-06-25 01:04:00 Play in the clouds

i++ First use and then add ;++i It's adding before using
If you don't understand, look at the case :
Case study 1:

int i=1;
i++;// Use first, then add , The code goes to this line i Is still 1 unchanged ( First use )
System.out.println("i:"+i);// Come to this line i It has been used up , It's time to add so +1 yes 2
int j=1;
++j;// Add before use , The code goes to this line first +1, therefore j Turned into 2
System.out.println("j:"+j);// Post use so j yes 2

i- -,- -i Empathy
Case study 2:

int i=1;
int he= i++ + ++i ;//1+3
System.out.println(he);//4
		
int j=1;
int sum= j-- + --j ;//1-(-1)
System.out.println(sum);//0

Case study 3:

int i=1;
int sum=i++ + ++i + i-- + --i ;//1+3+3+1=8
System.out.println(sum);
原网站

版权声明
本文为[Play in the clouds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210543407190.html