why this unexpected variable change happens? [closed]

o<<"index("<<s.getTI()<<")= "<<s.pop()<<endl; //getTI prints 1.

You are assuming that s.getTI() is evaluated before s.pop(), which is not necessarily true. The order of evaluation of these operands is completely unspecified and, in fact, the pattern I usually see is roughly right-to-left evaluation.

Do the s.getTI() and s.pop() evaluations on separate lines of code.

Leave a Comment