Why the output of next code is 2 1 2
?
#include "iostream"
int main(int argc, const char *argv[])
{
int i = 0;
std::cout << i << std::endl << i++ << std::endl << ++i << std::endl;
return 0;
}
Because first i
is equal 2 but not zero, it means that the whole like of cout
is evaluated first
and then printed (not part by part). If so, then first value should be 1, but not 2, because i++
should increment i
after printing. Could you clarify?
EDIT:
The output of next code is 2 2 0
.
#include "iostream"
int main(int argc, const char *argv[])
{
int i = 0;
std::cout << i << std::endl << ++i << std::endl << i++ << std::endl;
return 0;
}
why?