Interactive quiz on C if statements.
int a = 10; if (a == 10) { printf("It's A\n"); a = 20; } printf("a = %d\n", a);
a==10 is true → the if body runs → "It's A" is printed → a becomes 20 → the final printf shows the current value of a (20).
int a = 3; if (a = 10) { // = is assignment! (meant ==) printf("entered\n"); } printf("a = %d\n", a);
a = 10 is an assignment expression whose value is 10 (non-zero = true). So the if body executes, and a is now 10, making the final print show a = 10.int x = 5; if (x > 0 && x < 10 || x == 100) { printf("OK\n"); }
&& has higher precedence than ||, so this is effectively (x>0 && x<10) || x==100.