0
Can anyone help me to understand?
What is the difference between i++ and ++i? Can anyone explain this with example?
16 ответов
+ 2
The defference between ++1 and 1++ is that ++1 is a pre increment which increments or adds one to value i before using it while i++ is a post increment that adds one or increments i after using it (its same as i+=1 or i=i+1)
Example 1
int a =2;
Int b=++a; in this case before assigning a to b a is added 1 first then assigned to b so that a becomes 3 and 3 is assigned to b.
Example 2
Int a=2;
Int b=a++;
Here a is first assigned to be then after that its added one so that b =2 then a will have value 3
+ 7
I don't think there is increment and decrement operators are available in python
+ 5
i=2
5+ i++ will give us 7
5+ (++i) will give us 8
+ 4
++i will increase the value of i by 1 before using it and i++ will increase the value of i by 1 after next step of program(you can say it by the next line or by the next step to loop).
++i or i++ will increase the value of i by 1 in every time when this is written in program, not matter where is it (for example int a = i++, it will assign the value of i and it will also increase the value of i)
+ 3
++i increments the value of i by 1 before operation and i++ increments the value of i by 1 after operation
+ 2
They are same
+ 2
a = ++i // "i"will be increamented first then it will be assigned to "a"
a = i++ // "i" will be assigned to "a" first then it will be increamented.
+ 1
Asr bro ,
By mistake tagged wrongly
+ 1
Arun Venkatesh.N no worry it just use to increase or decrease the value and in this the main thing which you have to learn is that about the operator precedence and how ++ -- works with big expression once search on YouTube you can find better tutorials with great explanations
+ 1
Love this explanation thanks
+ 1
i++ and ++i both are increment operators ,but the thing is
i++ means==>post increment
++i means==>pre increment
i++ returns the value, first it increment the "i" value by one and then prints "i " value
++i returns the value, first prints the "i" value and the increment value of "i"
Both results gives same output
0
What is different between it engineer and software engineer
0
Anytime🚀
0
In java Write a program that computes the total sales tax on a $85 purchase. Assume the state sales tax is 5.5 percent and the county sales tax is 2 percent. Display the purchase price, state tax, county tax, and total tax amounts on the screen.