ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
int n = 1200, r = 0;
while (n) { r = r * 10 + n % 10; n /= 10; }
printf("%d", r);- A. 2100
- B. 0021
- C. 21
- D. 12
Correct answer: C. 21
The loop builds the reversed number arithmetically: 0, 0, 2, 21. Leading zeros of the reversed digits contribute nothing to an int, so the result is 21, not 0021.
More C Programming questions
- What is printed? c enum { R = 4, W = 2, X = 1 }; int perm = R | X; perm |= W; perm &= ~R; perm ^= X; printf("%d %d", perm, (perm & W) != 0);
- What is printed? c printf("%d", 5["abcdef"] - 'a');
- What is printed? c const char s = ""; int n = 0; for (int i = 0; i < strlen(s) - 1; i++) { n++; if (n > 5) break; } printf("%d", n);
- What is printed? c int pm(int b, int e, int m) { if (e == 0) return 1 % m; int h = pm(b, e / 2, m); h = h h % m; return e % 2 ? h b % m…
- What is printed? c #define STR(x) #x printf("%zu", strlen(STR( a + b )));
- What is printed? c char g[3][4] = {"abc", "def", "ghi"}; for (int j = 0; j < 3; j++) putchar(g[2 - j][j]);