+ 5

Chanllenge problem

When I have a chanllenge in C++,a problem that I can't catch is that: int x=2; cout<<(x- ++ --x); why the output is 0? what is meaning of "-";

15th May 2019, 3:35 PM
Jesscar🇨🇳🇭🇰
Jesscar🇨🇳🇭🇰 - avatar
13 Answers
+ 7
If x ++ will be collected Int x = 5; Int y = 10; cout << ++ x + y; _________________________________ Int x = 5; Int y = 10; cout << x ++ + y; If ++ x will ignore the variable because it is after x But its x ++ values ​​will remain unchanged But will display if you eject x again Will collect 1 + x and thus the result will become {6} In the other direction I did count << x; _________________________________ I hope you understand my words and if you want to understand the more I have in the conversation
15th May 2019, 11:13 PM
Abduo Saber
Abduo Saber - avatar
+ 3
Ok,I get it,maybe I have never seen this usage before,haha.Thanks
15th May 2019, 3:51 PM
Jesscar🇨🇳🇭🇰
Jesscar🇨🇳🇭🇰 - avatar
+ 3
Due to operator precedence. Answer will be zero
18th May 2019, 10:25 AM
Muhammad Rashid
Muhammad Rashid - avatar
+ 2
But there is operater precedence.
15th May 2019, 3:49 PM
surendra singh
surendra singh - avatar
+ 2
👍🤗
15th May 2019, 3:52 PM
surendra singh
surendra singh - avatar
+ 2
👍
15th May 2019, 4:04 PM
surendra singh
surendra singh - avatar
+ 1
I think it's equal to : x - (++ (--x)) ; So it's the same than x - x
15th May 2019, 3:41 PM
Théophile
Théophile - avatar
+ 1
But I think that operator is not vaild because between '-' and '++',there is no brackets,this is so confused
15th May 2019, 3:47 PM
Jesscar🇨🇳🇭🇰
Jesscar🇨🇳🇭🇰 - avatar
+ 1
So are there compilers where the output can be different? Or code is always translated in the same way?
15th May 2019, 3:59 PM
Théophile
Théophile - avatar
+ 1
Thanks!
15th May 2019, 4:02 PM
Théophile
Théophile - avatar