The program doesn't work because you are using assignment operator where you need to use the equality check operator. That is why the results are opposite and not what you had expected, as Richard said above.
What happens is that if(x = 0) would resolve the expression to zero. In C/C++, integers are directly resolved to boolean, everything non-zero is a true value and zero is the false. Since this resolves to zero, the expression is false and control is transferred to the
else
block.
Re-write it in this manner,
#include <stdio.h>
void main()
{
int x = 0;
if (!x) { printf("Its zero\n");
}
else {
printf("Its not zero\n");
}
}
Also remember to add the
{ }
around the statements, it is not a good practice as you may confuse yourself or add a semicolon by mistake, compiler will not complain but the logic would be wrong.
For more on C operators please refer to this tutorial:
http://www.tutorialspoint.com/cprogramming/c_operators.htm[
^]