GATE Computer ScienceVery hardGATE CS (PYQ pattern)
char src[] = "gate\0cse"; char dst[20]; char *d = dst, *s = src; int n = 0; while ((*d++ = *s++)) n++; printf("%d %zu %zu", n, sizeof(src), strlen(dst)); What is printed?
- A. 8 9 4
- B. 4 8 4
- C. 4 9 4
- D. 4 9 8
Correct answer: C. 4 9 4
The loop copies up to and including the first '\0' (after "gate") and stops, so n = 4 (the terminator is copied but not counted). sizeof(src) counts the characters g a t e \0 c s e plus the final implicit \0 = 9, and strlen(dst) = 4.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- What is the total number of characters written to the output by this program? (Assume arguments of the last printf are evaluated before…
- 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…
- 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…