I run the following C program
#include <stdio.h>
int main() {
int x = 5, y = 6, z = 3, i;
i = y > x > z;
printf("%d\n", i);
}
and get the output as 0
.
Again, when I run
#include <stdio.h>
int main() {
int x = 5, y = 6, z = 3, i;
i = y > x && x > z;
printf("%d\n", i);
}
I get output as 1
. Can anyone explain the logic behind this?
In first example, associativity of
>
operator left to right, So, First parsedy > x
and gives boolean result.then,
So, output
0
.In Second,
>
operator higher precedence then&&
operator. So, first parsedy > x
and if condition True, then checkx > z
.