GATE Computer ScienceHardGATE CS (PYQ pattern)
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; default: s += 1000; } if (i == 4) break; } printf("%d", s); What is printed?
- A. 1122
- B. 2132
- C. 2122
- D. 2012
Correct answer: C. 2122
i = 0: 11; i = 1 skipped; i = 2: 1100; i = 3: 1000; i = 4: 11 and then break. Sum = 2122.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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; }…
- Assume 4-byte int and 8-byte pointers. char s[] = "ab0cd"; char p = "ab0cd"; int a[3][4]; printf("%zu %zu %zu %zu %zu", sizeof(s)…