jeudi 4 juin 2020

Is cout << (i++) << (i++) Undefined behavior [duplicate]

I'm thinking what the output of int i = 0; cout << (i++) << (i++); is in c++11.

As my understanding, this code can be transformed into operator<<(operator<<(cout, i++), i++). Am I right?

I thought it would print 01, however, in my Ubuntu system, it printed 10.

Why? Is it an UB or not? If it's an UB, does it mean that f(g(i++), i++) is UB too? If it's not an UB, why was the output 10, instead of 01?

Aucun commentaire:

Enregistrer un commentaire