#include<stdio.h>
main()
{
int x = 5, y = 10, z = 10;
x = y == z; // This computational expression causes the value of x to be 1. I fail to understand why
printf("%d\n", x); //Why is the value of x 1 here.
}
I fail to understand the statement x = y ==z;
According to me – x = 10 since y == z. z=10 and is stated to be equivalent to y. The value of y is then assigned to x – x = y
You assign the result of the comparison »Is
yequal toz« tox, which is1, i.e. true.Note the different operators:
Let’s break the program down a little bit further:
xto 5 andyandzto 10.yandzwithout caring for the result. So that’s a line that can safely be ignored. But it results in1sinceyis equal toz.x.xnow has the value »Isyequal toz«, which is1in this case.