+ 1
I confuse about ++a and a++?
Help me please
3 Antworten
+ 2
Both commands do the same, add 1 into variable a like if you write
a=a+1;
++a and a++ are the same when it is a standalone command.
But there is a big difference, when you combine it with another command.
For example :
b=a++; or b=++a;
or in conditions if, or while, etc..
a++ add 1 after exetution this command, --a before it, So results are different. Try it
+ 2
when you use pre increment (++a) it first add 1 to a and then use the new value of a for the operations, in other hand on post increment (a++), it first uses the current value of a for the operations and then add 1 to the value of a.
+ 1
literally x =1; ++x will make x equals to 2 and x++ will makes x=1 and next time x=2