As an assignment for my beginner C++ course I'm writing a stack that holds strings (char tables). It has an overloaded "operator const char*()" that should enable me to use it's pop method in couts. Most of the time it seems to work nicely, but if I try to pop more than one element in a single line, like this: cout<<s.pop()<<endl<<s.pop<<endl;, it prints the values in reverse order. If I use two couts in two lines, it works well.
It is because of sequence points (go look it up on wikipedia if you don't know what that is).
The order of function calls on line 10 is undefined, for VC++, it seems to go right to left, so it will call the right zdejmij() first, giving it 2, then call the first one, giving it the value 1. However, like I said, it is undefined, so the program could do it in any order it feels like.
The << doesn't guarantee that the operands are evaluated from left to right so the second pop may be called before the first one and as a result you'll get the values to be printed in reverse order