int main()
{
int i=4 , z = 12;
if(i = 5 || z > 50)
printf("Inside if %d",i);
else
printf("Inside else %d",i);
}
Output : Inside if 1
This is because of precedence, this expression is evaluated as i = (5||z>50) as 5 is a non zero number so it evaluates as true and printf inside if is executed.
Logical OR has higher precedence than assignment operation.
Source: http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm
A few variations for more clarity:
int main()
{
int i=4 , z = 12;
if(i = 5 && z > 50)
printf("Inside if %d",i);
else
printf("Inside else %d",i);
}
Output : Inside else 0
int main()
{
int i=4 , z = 12;
if(i = 0 || z > 50)
printf("Inside if %d",i);
else
printf("Inside else %d",i);
}
Output: Inside else 0