0
Can anybody explain why x+=y-- is 16 not 15?? Here's the question: Int x=8; Int y=7; x++; x+=y--
Please...
9 odpowiedzi
+ 4
For example
x=10
y=6
x+=y--
Post decrement operator, will execute the operation first before decrease its value, that means
10+=6--
Is still 16, but after the operation ends y (in this case is 6) change to 5.
+ 9
● precedence of addition assignment operator is less than post decrement operator so it will be evaulated later
● associativity of post decrement operator is from left to right & associativity of addition assignment operator is from right to left
int x=8;
int y=7;
x++;
//x is 9 now
x+=y-- //x = 9 + 7
//y is 6 now & x will be 16
+ 2
Here's the question:
Int x=8;
Int y=7;
x++;
x+=y--
+ 2
Resultant value will be 16 as
In line 3 X incremented to value 9.
And in line 4 we are using post decrement operator with y which will add value of y ,which is 7 first and then make it 6 .
Hence resultant value will be 9+7=16.
If we print y on the next line then we will see it's value as 6.
+ 1
What is the value of x after the following code?
int x = 8;
int y = 7;
x++; //x+1
x+= y--; //x=x+1+y-1;
//x=8+1+7-1
//x++
//y is 6 and x is 16
0
Thank you! This help me a lot!
0
I think ...
a=1o;
b=2;
a++
//a=10 post increment
int c=a+b;
//here a=11 and b=2
so is c=13
BUT if
++a;
//here a=11 Pre-increment
0
I had the same issue, perhaps this is what I missed?
What is the value of x after the following code?
int x = 8;
int y = 7;
x++;
x+= y--;
//x= (x++; x+=y) or 8+1->9+7 [(--) concerning only the value of y AFTER equation]
//y= (y--) or 8-1=7
The key point is 'VALUE OF X' ----'AFTER CODE'
I hope i got that right
0
Explain this program
What is the value of x after the following code?
int x = 8;
int y = 7;
x++;
x+= y--;