ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 1, b = 2, c = 3;
int result = a == 1 && b == 2 || c == 100;
printf("%d", result);- A. 0
- B. Compilation error: mixed && and || require parentheses
- C. 3
- D. 1
Correct answer: D. 1
&& binds tighter than ||, so this parses as `(a==1 && b==2) || (c==100)` = (1 && 1) || 0 = 1 || 0 = 1 (true).
More C Programming questions
- 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)…
- What is printed? c int x = 7; int result = x % 2 == 0 ? x / 2 : x 3 + 1; printf("%d", result);