+ 1
Can someone explain the difference between x++ and ++x for me in a dumb way? thanks!
I really don't get why you need ++x
10 odpowiedzi
+ 7
x++ use the value stored in x and then do x = x +1
++x do x = x + 1 and then use the new value stored in x in the rest of the statement...
Putting all together in an example:
x = 1;
y = ++x; // you will have y = 2 and x = 2
z = x++; // now you will have z = 2 and x = 3
+ 2
int x=5;
cout<<x++; //5
int x=5;
cout<<++x; //6
however,
int x=5;
x++;
cout<<x; //6
0
x++ is a like to 1 and ++x is a call time value is 1
0
x++ is a postfix operator and the value of x is incremented later. ++x is a prefix operator which first increments the value of x by 1. Lets take an example
x=5;
sum=++x + x++ ;
0
so its output will be 6 + 6 = 12. so 12 will be stored in sum. Got it !!
0
plz explian me also
0
yeah as above said 😉😉
0
x = 1
y = ++x
y = (x = x+1)
This causes:
x = x+1
y = x
[x = 2, y = 2]
y = x++
y = x, x = x+1
This means:
x = 1
y = x
x = x+1
[x = 2, y =1]
- 1
Explain it to yourself.
Enter a value of x then cout it. then use ++x and again cout <<x and for the last time use x++ and cout<<x again.
- 1
the ++a and a++ is a+1 so the two are same