Int x=4; Int y=2; Cout<<x++*y--; | SoloLearn: Learn to code for FREE!

+14

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

2/1/2020 1:13:19 AM

@Manoj.Codes

+8

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

Ok got it thank you sir

+3

+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 as you use post increment

+3

+3

+2

++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

+2

+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 since it is postfix,use the original values before u increment x and decrement y .

+2

+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.

+2