当前位置:网站首页>I++ and ++i details
I++ and ++i details
2022-07-29 04:28:00 【Yun Wenwu】
i++ And ++i Detailed explanation
i++ And ++i Not with assignment number (=) When connected, the effect is equivalent to i=i+1
Examples are as follows :
//++i
public class demo
{
public static void main(String[] args) {
int i=0;
++i;
System.out.println(i);
}
}
//i++
public class demo
{
public static void main(String[] args) {
int i=0;
i++;
System.out.println(i);
}
}
The output of both code blocks is 1
i++ And assignment number (=) At the same time, the performance takes precedence i And then add one
public class demo{
public static void main(String[] args){
int q;
int i=0;
q=++i;
System.out.println(q);
}
}

++i And assignment number (=) When it appears at the same time, add 1 Then take
public class demo{
public static void main(String[] args){
int q;
int i=0;
q=++i;
System.out.println(q);
}
}

Now we will i++ And ++i And assignment number (=) Put them together and discuss their order
public class demo
{
public static void main(String[] args) {
int q;
int i=0;
q=(++i)+(i++);
System.out.println(q);
System.out.println(i);
}
}

We put q=(++i)+(i++) Take it out and see
Before this step, our q Unassigned ,i The value of is 0,
When running here () The highest priority is to execute the things in brackets first. The first bracket indicates ++i take i+1 Assign to i, here i Turned into 1 Participate outside the brackets + Method operation is 1, Look at the second bracket i++ It means first i Value is assigned to i Give again i+1 here i by 2, But one thing to note ,i++ It is added after the assignment, so the value of the right bracket when participating in the addition operation outside the two brackets is ( Current value -1) namely 1. therefore q,i The value of will end up being 2
Now let's raise the difficulty , Add 3 individual
public class demo
{
public static void main(String[] args) {
int q;
int i=0;
q=(++i)+(i++)+(++i);
System.out.println(q);
System.out.println(i);
}
}

Carry it here alone q=(++i)+(i++)+(++i) This statement shows
Above this statement q No value ,i The value is 0
To this sentence, run from left to right in parentheses :
- In the first bracket 0+1,i The value of becomes 1,1 Participate in external operations
- In the second bracket 1+1,i The value of becomes 2,1 Participate in external operations
- In the third bracket 2+1,i The value of becomes 3,3 Participate in external operations
q To be an assignment 1+1+3 by 5,i Final value for 3
The above statement is equivalent to the following statement :
public class demo
{
public static void main(String[] args) {
int q;
int i=0;
int a=++i;
int b=i++;
int c=++i;
q=a+b+c;
System.out.println(q);
System.out.println(i);
}
}

边栏推荐
- 不会就坚持67天吧 平方根
- 不会就坚持68天吧 狒狒吃香蕉
- 不会就坚持69天吧 合并区间
- 不会就坚持62天吧 单词之和
- Not for 58 days. Implement prefix tree
- oracle 更新和删除数据
- leetcode 686.重复叠加字符串 KMP方法(C语言实现)
- Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)
- Machine vision series 3:vs2019 opencv environment configuration
- Multi card training in pytorch
猜你喜欢

Laya中的A星寻路

Introduction and examples of parameters in Jenkins parametric construction

The principle of inverse Fourier transform (IFFT) in signal processing

On the use of pyscript (realizing office preview)

12.优先级队列和惰性队列

Deep learning training strategy -- warming up the learning rate

Redux quick start

TypeError: Cannot read properties of undefined (reading ‘then‘)

No, just stick to it for 59 days

redux快速上手
随机推荐
Post export data, return
C语言:结构体简单语法总结
oracle 更新和删除数据
Jenkins 参数化构建中 各参数介绍与示例
LeetCode_ Stack topics
C language: typedef knowledge points summary
C language: talking about various complex statements
C语言:typedef知识点总结
MySQL gets the maximum value record by field grouping
[common commands]
Labelme cannot open the picture
Don't stick to it for 68 days. Baboons eat bananas
Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)
On quotation
异常处理:pyemd或PyEMD找不到
不会就坚持70天吧 数组中第k大的数
C language: summary of consortium knowledge points
Won't you just stick to 69 days? Merge range
9.延迟队列
[k210 stepping pit] pytorch model is converted to kmodel and used on dock. (ultimately not achieved)