GATE Computer ScienceModerateGATE CS (PYQ pattern)
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?
- A. 5 -2 -10 -2
- B. 5 -2 5 5
- C. 5 2 5 2
- D. 5 -2 5 -2
Correct answer: D. 5 -2 5 -2
Assignment binds tighter than the comma operator, so the second line is (k = (i += j)), (j -= i), (i * j): k = 5, then j = 3 - 5 = -2, and i * j is computed and thrown away. In m = (i, j) the parentheses make the comma expression yield its right operand, -2.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- void p(int n) { if (n == 0) return; printf("%d ", n); p(n - 1); printf("%d ", n 10); if (n % 2 == 0 && n > 2) p(n - 2); } How many numbers…
- void f(int x, int y, int z) { x = y + z; y = x - z; z = x; } int main() { int a = 1, b = 2, c = 3; f(&a, &b, c); f(&b, &a, c); f(&a, &a…