-5

I'm newbie in c++ and i am doing some exercises.

I have a code

#include <cstdlib>
#include <iostream>

using namespace std;
int main(void) {
int i=0;
int a,b,c;
a = i++;
b = i++;
c = i++;

cout << a << b << c;
return 0;
}

and, whe I run it, the result is: 012

But when I run it without variables a, b and c, like in following code

#include <cstdlib>
#include <iostream>

using namespace std;
int main(void) {
int i=0;
cout << i++ << i++ << i++;
return 0;
}

I get result in reverse order: 210

Why is this happening? I think it should be again 012 (I am using NetBeans)

Ray
  • 33
  • 1

1 Answers1

1

You are violating the rules of the language that has multiple increment and decrement in the same expression or as different arguments to the same call as undefined.

George Houpis
  • 1,729
  • 1
  • 9
  • 5