Search:
Forum
Beginners
Order of operations/precedence
Order of operations/precedence
Jul 16, 2013 at 4:32pm UTC
InstantDeath
(5)
could someone explain to me why the answer would be 3?
1
2
3
4
5
int
a = 5; a -= a-- - --a; cout << a;
Last edited on
Jul 16, 2013 at 4:32pm UTC
Jul 16, 2013 at 4:34pm UTC
vlad from moscow
(6539)
The code has undefined behaviour.
Jul 16, 2013 at 4:35pm UTC
InstantDeath
(5)
Are you saying its not valid? because its valid.
Jul 16, 2013 at 4:39pm UTC
JLBorges
(13770)
See:
http://en.cppreference.com/w/cpp/language/eval_order
Jul 16, 2013 at 4:42pm UTC
Smac89
(1727)
a -= a--(5) - --a(4-1)
5 -= 5 - 3
5 -= 2
3
http://stackoverflow.com/a/4706225/2089675
I have my doubts however that this is actually how it works, but if it does the way I showed is how it would be evaluated
Last edited on
Jul 16, 2013 at 4:45pm UTC
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs