0

What is different between i++ and ++i ?

16th Apr 2021, 5:14 AM
Rahima Mirzad
Rahima Mirzad - avatar
5 Respuestas
+ 3
I++ (postfix)means first use then increase and ++I (Prefix)means first increase and then use
16th Apr 2021, 5:39 AM
Atul [Inactive]
+ 3
Post-Increment (i++) : Value is first used for computing the result and then incremented. Pre-Increment (++i): Value is incremented first and then result is computed.
16th Apr 2021, 5:39 AM
SAN
SAN - avatar
+ 2
I++ and ++I are increment operators. I++ is post increment. It means first it assign a value to variable then it will increment. For Example, i=1; J= i++; J=i+1; So J= i => j=1 then J= 1+1= 2; So finally the value of J = 2; ++I is pre increment operators. It means first increment then assign to value. J= ++i; J=1+i; i=1; So, J=1+i=> J= 1+1= 2;
17th Apr 2021, 1:36 PM
Vamsi Chowdary
Vamsi Chowdary - avatar
16th Apr 2021, 5:41 AM
Atul [Inactive]
+ 1
The other answers about increments are great. You still also need to understand both decrements, too. i-- and --i. So... i++ If i == 1, this operator will calculate the line where it was used, then set i=2. ++i If i == 1, this operator will set i=2, then calculate the line where it was used. i-- If i == 1, this operator will calculate the line where it was used, then set i=0. --i If i == 1, this operator will set i=0, then calculate the line where it was used.
16th Apr 2021, 6:06 AM
Phil Andy Graves
Phil Andy Graves - avatar