In C++, the output starts from right or left ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In C++, the output starts from right or left ?

Int a=0; Cout<<a++<<++a<<a<<a++; //Output: 0222 or Output: 2210 ??

4th Dec 2018, 7:36 PM
Vishal Shriwal
Vishal Shriwal - avatar
3 Answers
+ 7
Very interesting UB ¹! The compilation log: "warning: operation on 'a' may be undefined [-Wsequence-point]" Reason: "When modifying an object between two sequence points, reading the value of the object for any other purpose than determining the value to be stored is also undefined behavior." _____ ¹ https://en.wikipedia.org/wiki/Undefined_behavior#Examples_in_C_and_C++
4th Dec 2018, 7:46 PM
Babak
Babak - avatar
+ 2
Felix Moelder, C++ Soldier (Babak) - Thanks for the information. 🙂
4th Dec 2018, 8:05 PM
Vishal Shriwal
Vishal Shriwal - avatar
+ 1
From left to right
4th Dec 2018, 7:42 PM
Felix Moelder
Felix Moelder - avatar