GATE Computer ScienceVery hardGATE CS (PYQ pattern)
unsigned char a = 250, b = 10; unsigned char c = a + b; int x = -1; unsigned int y = 1; printf("%d %d %d %d", c, a + b, x < y, (unsigned char)(a * 2) >> 1); What is printed?
- A. 4 260 1 250
- B. 4 260 0 122
- C. 260 260 0 250
- D. 4 4 1 122
Correct answer: B. 4 260 0 122
a + b is computed in int: 260, stored into unsigned char gives 4. In x < y, x converts to unsigned (4294967295), so the comparison is 0. a * 2 = 500, cast to unsigned char is 244, shifted right by 1 is 122.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- int s = 0; for (int i = 0; i < 6; i++) { if (i == 1) continue; switch (i % 4) { case 0: s += 1; case 1: s += 10; break; case 2: s += 100…
- A recursive routine place(r) tries every column c for row r, recursing only if column c and both diagonals are free of earlier queens; at…
- Binary search (lo = 0, hi = n - 1, mid = (lo + hi) / 2 with integer division) is run on a sorted array of the 100 elements 1..100 once for…
- rot(a, n, k) does: reverse(a, 0, k-1); reverse(a, k, n-1); reverse(a, 0, n-1), where reverse(a, i, j) reverses a[i..j] in place. The array…
- int x = 10; void f() { static int x = 1; x += 2; { int x = 100; x++; } printf("%d ", x); } int main() { f(); f(); { extern int x…
- unsigned char rev(unsigned char x) { unsigned char r = 0; for (int i = 0; i < 8; i++) { r = (r << 1) | (x & 1); x >>= 1; } return r; }…