0

I have just typed a peace of code but I am getting weird result , so what can be the possible reason?

#include <iostream>
using namespace std;
int main()
{
    int a = 5, b = 5;
    cout << a++ << endl << ++a << endl;
    cout << ++b << endl << b++;
    return 0;
}

EXPECTED OUTPUT

            5
            7
            6
            6

OUTPUT I AM GETTING

            6                                                                                                                                             
            7                                                                                                                                             
            7                                                                                                                                             
            5 
Andrew
  • 49
  • 4
  • 1
    _Undefined behavior_ may be? No need in YELLING by the way. – πάντα ῥεῖ Apr 18 '21 at 18:05
  • https://stackoverflow.com/questions/5214611/unexpected-order-of-evaluation-compiler-bug and https://stackoverflow.com/questions/33445796/increment-and-decrement-with-cout-in-c talk about it. – Jose Apr 18 '21 at 18:07

0 Answers0