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?

  1. A. 4 260 1 250
  2. B. 4 260 0 122
  3. C. 260 260 0 250
  4. 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.

More Programming and Data Structures (GATE) questions

Exams that ask this topic