GATE Computer ScienceHardGATE CS (PYQ pattern)
What is the total number of characters written to the output by this program? (Assume arguments of the last printf are evaluated before the call.) int n = printf("%5d|%-4d|", 42, 7); int m = printf("%d", n); printf("%d", m + printf("%03d", n));
- A. 16
- B. 18
- C. 20
- D. 17
Correct answer: D. 17
First printf writes ' 42|7 |' = 11 chars and returns 11. printf("%d", 11) writes 2 and returns 2. Inner printf("%03d", 11) writes '011' (3) and returns 3, then the outer prints 2 + 3 = 5 (1 char). Total 11 + 2 + 3 + 1 = 17.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- 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…