+ 1
Prefix and postfix
Can someone show me the difference of x++ and ++x
4 ответов
+ 16
x++ increments after the line ends
and ++x increments on the same line....
for eg.:-
int x=4;
int y=x++; //here y=4. & x will be incremented in next line
cout<<x<<y;
outputs:- 54
eg.2:-
int x=4;
int y=++x; //here x is incremented on the same line & so y=5.
cout<<x<<y;
outputs:- 55
consider 1 more eg.:-
int x=4;
x+=x++; // value of x becomes 8 & then it gets incremented on next line...
cout<<x;
outputs:--9
eg:-2
int x=4;
x+=++x; // x=x+(++x) here value of x becomes 5 first & then operated..
cout<<x;
outputs:--10
+ 11
x++ increase expression after line with this part of code. ++x - while doing
+ 2
have a look at these lesson
https://www.sololearn.com/learn/CPlusPlus/1610/?ref=app
the are in total 5 slides
go through all