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.