GATE Computer ScienceHardGATE CS (PYQ pattern)
unsigned int i, s = 0; for (i = 5; i-- > 0; ) s += i; printf("%u %u", s, i); What is printed?
- A. 10 0
- B. 15 4294967295
- C. 10 4294967295
- D. 10 4294967294
Correct answer: C. 10 4294967295
The condition i-- > 0 tests the old value and then decrements, so the body sees i = 4, 3, 2, 1, 0 (sum 10). After the last test (0 > 0 false) i is decremented once more to 0 - 1 = 4294967295 (unsigned wrap).
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 = 7, b = 2; float f = a / b + a / 2.0 + (float)(a / b) b; printf("%.2f %d", f, (int)(a / b 2.0)); What is printed?
- 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)…
- 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…