I would like to know how i is evaluated in this code in C language ?
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n",i);
I would like to know how i is evaluated in this code in C language ?
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n",i);
Copyright © 2021 Jogjafile Inc.
The result of a relational operator is either integer 1 if the condition is true or 0 otherwise. And relational operators evaluates from left to right.
So this statement
is equivalent to
and as x is less than y then it can be also rewritten like
that initialize the variable i by 1 because 1 is less than 5.
From the C Standard (6.5.8 Relational operators)
If you will rewrite the statement like
then the result of the expression will be equal to 0 because y is not less than z.