+ 1

# What is the output of this program?

#include <iostream> int main() { int a = 0; std::cout << (++--++a)++ + ++a; return 0; }

3 Answers

+ 2

The output should be 4...
Why? ++--++ is the same as ++ so you could rewrite your expresion as: (++a)++ + ++a... What happends then? the value in a is incremented two times before the addition leaving: (2)++ + 2 which is equal to 4... after that, a is incremented by one one more time leaving the value in a equal to 3... but as I said before, what you get on screen is 4 which is the sum of a before the last increment...

0

But in this program the order of operations are well defined...

0

Error