Q:

An unexpected output for C++ code.Can someone explain?

I came across this code while doing random search and I though to execute it on www.ideone.com and the output came 0 while I was expecting it to be 10.
#include <iostream>
using namespace std;

int main() {

    int count = 0; 
for(int i=0; i < 10; ++i) 
 count = count++; 

std::cout << count; 
    return 0;
}

As far as my understanding is, count = count++; can be assumed as count = count; and count = count + 1; So shouldn't the output be 10 instead of 0?What is the reason for such a behaviour?
NOTE: As pointed out by comments here that this question comes under "Undefined Behavior and Sequence Points", I want to just make it clear that as I am new to C++, I didn't knew that these are undefined behavior.So, I hope everyone will forgive for mistake.

A:

The line that is the problem is count = count++;.  For a ridiculously detailed description of what is wrong, read Undefined behavior and sequence points.
Basically, you come to the problem of which evaluates first, the assignment to count from the = operator or the assignment to count from the ++ operator.  If it evaluates the assignment from the ++ operator first, then you will get 0.  If it evaluates the = before the assignment from the ++, then you will get 10.

