ProgrammingHardTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int rev(int n, int acc) {
return n == 0 ? acc : rev(n / 10, acc * 10 + n % 10);
}
int main(void) {
printf("%d", rev(1234, 0));
}- A. 1234
- B. 4312
- C. 3421
- D. 4321
Correct answer: D. 4321
The accumulator takes the last digit each time, so the digits come out reversed: 4, then 43, 432 and 4321.
More C Programming questions
- What is printed? The program checks whether the low four bits of each argument form a binary palindrome. c #include <stdio.h> unsigned…
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 1, r = 0; for (int i = 0; i < 32; i++)…
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 1000; int p = -1; while (n) { n >>= 1; p++; } printf("%d", p); }
- Would the product of 50000 and 50000 overflow a 32-bit int? The program checks with a 64-bit product. What is printed? c #include…
- What is printed? c #include <stdio.h> int main(void) { const char s = "112233"; int count[10] = {0}; for (const char p = s; p; p++)…
- What is the trace of the matrix product A B, where A = {{1, 2}, {3, 4}} and B = {{5, 6}, {7, 8}}? Compute with this program. c #include…