Can anyone help me to understand? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone help me to understand?

What is the difference between i++ and ++i? Can anyone explain this with example?

8th Oct 2022, 7:39 AM
Venkatesh
Venkatesh - avatar
15 Answers
+ 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
9th Oct 2022, 11:07 PM
David Mwas
David Mwas - avatar
+ 7
I don't think there is increment and decrement operators are available in python
8th Oct 2022, 8:00 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 5
i=2 5+ i++ will give us 7 5+ (++i) will give us 8
8th Oct 2022, 11:47 AM
Omanshu
Omanshu - avatar
+ 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)
9th Oct 2022, 11:59 AM
Rajeev Sharma
Rajeev Sharma - avatar
+ 3
++i increments the value of i by 1 before operation and i++ increments the value of i by 1 after operation
8th Oct 2022, 11:46 AM
Omanshu
Omanshu - avatar
+ 2
They are same
9th Oct 2022, 4:05 PM
Nwanebike Daniel
Nwanebike Daniel - avatar
+ 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.
10th Oct 2022, 2:29 AM
Muhamad Iqbal Chaniago
Muhamad Iqbal Chaniago - avatar
+ 1
Asr bro , By mistake tagged wrongly
8th Oct 2022, 8:10 AM
Venkatesh
Venkatesh - avatar
+ 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
8th Oct 2022, 8:17 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Love this explanation thanks
9th Oct 2022, 11:25 PM
Morgan Michael
+ 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
10th Oct 2022, 7:25 AM
Veerendra Babu
Veerendra Babu - avatar
0
What is different between it engineer and software engineer
9th Oct 2022, 3:13 PM
Shachin Tiwari
Shachin Tiwari - avatar
0
Anytime🚀
10th Oct 2022, 12:00 AM
David Mwas
David Mwas - avatar
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.
10th Oct 2022, 7:03 AM
Mohit Rahtan