ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int a = 5, b = 2, c = 3;
int result = a > b > c;
printf("%d", result);- A. 5
- B. 1
- C. 0
- D. Compilation error: chained comparisons are not allowed
Correct answer: C. 0
Unlike Python, C has no chained comparisons: `a > b > c` parses as `(a > b) > c`. (5 > 2) evaluates to 1 (true); then `1 > 3` is false, giving 0 — a common trap for programmers coming from Python.
More C Programming questions
- What is printed? c int a = 1, b = 2, c = 3; int result = a == 1 && b == 2 || c == 100; printf("%d", result);
- What is printed? c int a = 4; int b = ~a + 1; printf("%d %d", b, -a);
- What is printed? c int x = 1, y = 2, z = 3; int result = x < y < z; printf("%d", result);
- What is printed? c int a = 5; int b = a++ + ++a; printf("%d %d", a, b);
- What is printed? c int a = 0; int b = (a = 5) == 5; printf("%d %d", a, b);
- What is printed? c #define ISEVEN(x) ((x) % 2 == 0) #define ISODD(x) (!ISEVEN(x)) int main(void) { int n = 7; printf("%d %d", ISEVEN(n)…