+ 2

someone should tell me how it works, with full description 😷

int x = 4 int y = 3 cout << ++x*y-- ; output: 15

29th May 2017, 8:59 PM
Dhruba
Dhruba - avatar
12 ответов
+ 15
first will execute ++x --> x = 5 second will execute x*y --> 5*3 = 15 third will print the result "15" forth will ecexute y-- --> y = 2
29th May 2017, 9:05 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 14
this is the order in which it all happens: 1) ++x increments x from 4 to 5 2) x*y -> 5*3 = 15 3) y-- decrease y to 2 (the calculation in 2 has already been made so that is the final output) 4) if you were to check the value of y you'd see it is now 2
29th May 2017, 9:07 PM
Burey
Burey - avatar
+ 13
thanks guys helpful for me too...
30th May 2017, 1:28 AM
Ishwarya Manikandan
Ishwarya Manikandan - avatar
+ 12
it works after the execution of the expression. ex: int x = 4; int y = 3; cout << ++x*y--; // will output 15 cout << y; // now value of y change and will output 2
29th May 2017, 9:16 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
with prefix ++x will increment x by 1 then execute the expression, while in postfix y-- will execute the expression then decrement the value of y by 1.
29th May 2017, 9:08 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
int x = 5; int y = 3; cout << ++x*y--; it shows 18 not 15 but if you mean cout << x++ * y--; it will shows 15
29th May 2017, 11:53 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
you'r welcome..
30th May 2017, 2:09 AM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 11
you'r welcome..😊
30th May 2017, 5:49 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 3
you mean there is no work for '--'?
29th May 2017, 9:11 PM
Dhruba
Dhruba - avatar
+ 1
all right but what's about that? int x = 5 int y = 3 cout << ++x*y--; it also shows 15?
29th May 2017, 9:37 PM
Dhruba
Dhruba - avatar
+ 1
yup, clear😊 thanks Dakdouk👌
30th May 2017, 5:05 PM
Dhruba
Dhruba - avatar
+ 1
int x = 5; int y = 3; cout << ++x*y--; it shows 18 not 15//can you please explain why is it 18... does it mean only value of x was incremented but if you mean cout << x++ * y--;// and here why is it 15 it will shows 15
19th Jun 2017, 11:23 PM
Joe Justin
Joe Justin - avatar