Why is the output showing d=4 instead of d=8 in the first printf statement
#include <stdio.h>
int main() {
int a = 3, b = 4, c = 3, d = 4;
int y = (c = 5) || (d = 8);
printf("a=%d, b=%d, c=%d, d=%d\n", a, b, c, d);
}
Why is the output showing d=4 instead of d=8 in the first printf statement
#include <stdio.h>
int main() {
int a = 3, b = 4, c = 3, d = 4;
int y = (c = 5) || (d = 8);
printf("a=%d, b=%d, c=%d, d=%d\n", a, b, c, d);
}
||
short circuits, so in:
y = (c = 5) || (d = 8);
The d = 8
is never evaluated.
That is, since (c = 5)
evaluates as true, there is no reason to evaluate the (d = 8)
to determine the truthiness of the expression; so it is not evaluated.