GATE Computer ScienceVery hardGATE CS (PYQ pattern)
int a = 5, b = 3, c = 2; int x = a + b << c > 20; int y = 6 & 3 == 3; int z = 1 + 2 * 3 % 4 - 5 / 2 | 8 >> 2; printf("%d %d %d", x, y, z); What is printed?
- A. 1 2 3
- B. 1 0 3
- C. 0 0 3
- D. 1 0 1
Correct answer: B. 1 0 3
Precedence: + above <<, << above >, == above &, and * % / above + -, which are above >> which is above |. x = ((5+3) << 2) > 20 = 32 > 20 = 1. y = 6 & (3 == 3) = 6 & 1 = 0. z = ((1 + (6 % 4) - 2) | (8 >> 2)) = (1 + 2 - 2) | 2 = 1 | 2 = 3.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int C(int n, int k) { if (k == 0 || k == n) return 1; if (k == 1) return n; return C(n - 1, k - 1) + C(n - 1, k); } How many calls to C…
- Elements 1, 2, 3, 4, 5, 6 are pushed in this order onto a stack, with pops allowed at any time until all are popped. Of all possible…
- An input-restricted double-ended queue lets items 1, 2, 3, 4, 5 be inserted only at the rear (in that order) while removals are allowed at…
- A hash table has 7 slots (0 to 6) and uses linear probing with h(k) = k mod 7. The six keys 8, 15, 3, 10, 5, 12 are inserted in some…
- The distinct keys 1..8 are arranged as a max-heap in a 0-indexed array of size 8 (children of i at 2i+1, 2i+2). Over all valid max-heaps…
- Heapsort (max-heap, in-place) is applied to [9, 4, 7, 1, 8, 2, 6, 3, 5, 10, 12, 11, 15, 14, 13]. First the array is made a max-heap with…