Consider following code:
#include <iostream>
int main()
{
int i = 0;
std::cout << ++i << ' ' << --i << std::endl;
}
In his "C++17 The Complete Guide" book Nicolai Josuttis writes that before C++17 this particular example might produce unpredictable results. Both 1 0
and 0 1
might be produced but what's more 0 0
is also a possible output. I don't get why the third sequence should be considered as possible. Either ++i
or --i
should be evaluated before the second value is evaluated which by definition cannot produce two zeros, shouldn't it?