0
Wt is difference between x++ and ++x
4 Antworten
+ 14
this will help you to understand more about increment decrement
https://www.sololearn.com/Discuss/407846/?ref=app
+ 8
https://www.sololearn.com/learn/CPlusPlus/1610/?ref=app
+ 2
Supoosing x=5
and we use x++, so that will use the current value of x(that is 5) and then after using it one time, it will add 1 to x.. so its value becomes 6.
for example..
int y=x++; // y= 5
System.out.println(x); // prints 6
And if we use ++x, it just simply adds 1 to x, and then uses it,
For example
int y=++x // y= 6
System.out.println(x); // prints 6
+ 1
x++ returns the current value of x then increments x by 1
++x incrementa x by 1 then returns the new value
int x = 0;
int a = x++; // a is 0, x is 1
int b = ++x; // b is 2, x is 2