0
What is different between i++ and ++i ?
5 Respuestas
+ 3
I++ (postfix)means first use then increase and ++I (Prefix)means first increase and then use
+ 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.
+ 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;
+ 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.