mercredi 6 juillet 2016

How is the evaluation of integer incrementation in chain of std::cout done? [duplicate]

This question already has an answer here:

Consider

auto a = 0;
std::cout << a;
std::cout << a++;
std::cout << ++a;
std::cout << std::endl;

Output: 002

Which is expected regarding the post and pre incrementation rule.

However the following code

auto a = 0;
std::cout << a << a++ << ++a << std::endl;

Output: 212

Since the following seems to print number in the right order

auto a = 0;
auto b = 1;
auto c = 2;
std::cout << a << b << c << std::endl;

Output: 012

I am trying to figure out why I got 212 in the second case?

Full code is here: http://ift.tt/29nHvjC

Aucun commentaire:

Enregistrer un commentaire