+ 1
Can anyone explain how it works?
x=5,y=9; x=++x; y=--y; y-=x++; cout<<y;
8 Answers
+ 3
Get some help here
https://www.sololearn.com/learn/CPlusPlus/1610/
+ 2
Let me simplify it for you.
Then you may be able to understand
X=5,y=9;
x=x+1;//x=6
y=y-1;//y=8
y=y-x++//y=8-6 cause it is postfix it will return x's value first then increment x by 1.
May be now you can understand.
If not briefly explain the doubt.
+ 1
Ipang sure buddy...actually was a just bit confused ...so thought of posting that part only
+ 1
Yaa Bro ;-)
++ => Is increment operator which is unary operator too, it's means it work on single operand and this can be use as prefix and suffix if it's on prefix then it increment first then do other things like assiging printing etc but in suffix it's do other thing then do increment ok .
-- => Is decrement operator which is unary operator too, it's means it work on single operand and this can be use as prefix and suffix if it's on prefix then it decrement first then do other things like assiging printing etc but in suffix it's do other thing then do decrement ok
So, output must be 2.
0
Anant Jain bro...I have also read that topic....but still couldn't get that question....Can u explian deeply?
0
Try to run that snippet in Code Playground, you will get compile error first because the type for variable <x> and <y> is undefined.
Once you add type definition for variable <x> and <y>, try to run that snippet again. This time you might have an output plus some warnings. "The operation on x may be undefined" and "The operation on y may be undefined".
So what these warnings try to tell us? The warning tells us that we should not make an attempt to access and/or modify a data within a single point of execution sequence. This warning comes up because there are attempts to assign value (modify) variable <x> and <y> while the value to be assigned is read (accessed) from the same variable (<x> and <y> respectively).
0
And please use relevant tags, at least specify the relevant language of the code (C++ as it seems). It helps to improve context clarity of your question, and *may* increase your chances for relevant, effective and quality answers đ
0
Anant Jain Thank you bro