+ 12
Int x=4; Int y=2; Cout<<x++*y--;
Can anyone tell me output of this code with explanation . I'm trying to understand but still confusing in question
33 Respuestas
+ 10
x++: Increases x by 1, but returns the original value 4.
y--: Decreases y by 1, but returns the original value 2.
x++*y-- = 4*2 = 8
+ 3
++x: Increases x by 1 and returns the new value 5.
--y: Decreases y by 1 and returns the new value 1.
++x*--y = 5*1 = 5
+ 3
Ok got it thank you sir
+ 3
Oh sorry I read that by votes, I was answering your second question in the comments
+ 3
Ohk my mistake 😅
+ 3
As both x and y are post incremented or decremented , so the value assigned first and then gets incremented or decremented, so in cout statement value of x (i.e. 4) and y (i.e. 2) is used and then gets incremented and decremented respectively, hence results in 8.
+ 3
2*4=8
+ 3
8 since it is postfix,use the original values before u increment x and decrement y .
+ 3
8 as you use post increment
+ 3
8
+ 3
It's answer is 8
+ 3
First you multiply 2 and 4 and print 8
The reason:
In c++ it does the prefix then the math then the postfix so in this case it did the math then the postfix so if you tried to print out x value after that it will give you 5 and if you did the same for y it will give you 1.
+ 3
4*2=8. Post increment/decrement occurs after the expression is evaluated and output.
+ 3
The answer is 4*2=8
+ 2
X is incremented before multiplying to y and same goes for y. Answer is 5
+ 2
Wrong answer is 8
+ 2
Answer = 8.
causes, That's happen post increment and post decrement.
+ 2
x=5
y=2
case1:
cout<<++x*--y; //6*1=6
after evaluation x=6,y=1
case2:
cout<<x++*y--; //5*2=10
after evaluation x=6,y=1
+ 2
8
+ 2
Becoz in this there is post increment and Decrement operator .so it take values increase and decrease of only x and y after the multiplication.