GATE Computer ScienceHardGATE CS (PYQ pattern)
int a = 0, b = 0, c = 0; int r = (a++ && b++) || (++c && a++) || (b++ || ++c); printf("%d %d %d %d", r, a, b, c); What is printed?
- A. 1 2 1 1
- B. 1 1 0 1
- C. 1 2 0 1
- D. 1 2 0 2
Correct answer: C. 1 2 0 1
a++ yields 0 (a becomes 1), so b++ is skipped. ++c gives 1, then a++ yields 1 (a becomes 2), so the whole || chain stops before the last group. r = 1, a = 2, b = 0, c = 1.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- unsigned f(unsigned x) { unsigned c = 0; while (x) { x &= x - 1; c++; } return c; } unsigned g(unsigned x) { return x & ~(x - 1); }…
- int i = 2, j = 3, k, m; k = i += j, j -= i, i j; m = (i, j); printf("%d %d %d %d", i, j, k, m); What is printed?
- int a[] = {10, 20, 30, 40}; int p[] = {a, a + 1, a + 2, a + 3}; int pp = p; int t1 = pp++; int t2 = ++pp; int t3 = ++++pp; printf("%d %d…
- Assume char is 1 byte, int is 4 bytes with 4-byte alignment, double is 8 bytes with 8-byte alignment, and the compiler inserts only the…
- int cnt = 0; int f(int n) { cnt++; if (n <= 1) return 1; if (n == 2) return f(1) + 1; return f(n - 1) + f(n - 2) + f(n - 3); } After f(6)…
- int g(int n) { static int s = 0; s += n; if (n > 0) { g(n - 1); s += n; } return s; } int main() { int x = g(3); int y = g(2); printf("%d…