ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int a = 0, b = 0;
int x = (++a > 5) && (++b > 0);
int y = (++a > 0) || (++b > 0);
printf("%d %d %d %d", a, b, x, y);- A. 2 0 0 1
- B. 2 2 0 1
- C. 1 0 0 1
- D. 2 1 0 1
Correct answer: A. 2 0 0 1
&& stops when the left side is false (1 > 5 is false), so the first ++b never runs. || stops when the left side is true (2 > 0), so the second ++b never runs either. b stays 0.
More C Programming questions
- What is printed? c printf("%c %d %d", 'A' + 2, 'A' + 2, 'z' - 'a');
- What is printed? c unsigned char a = 250, b = 10, z = 0; int s = a + b; unsigned char t = a + b; z--; printf("%d %d %d", t, z, s);
- What is printed? c int x = 6; printf("%d %d", x & 2 == 2, (x & 2) == 2);
- What is printed? c int a = (1, 2, 3); int b = 5; b = (b + 1, b 2); printf("%d %d", a, b);
- What is printed? c void f(int n) { if (n > 0) { f(n - 1); printf("%d ", n); f(n - 2); } } int main(void) { f(3); }
- What is printed? c int a[2][3] = {{1, 2, 3}, {4, 5, 6}}; printf("%d %d %d", ((a + 1) + 2), (a[1] + 1), a + 1);