ProgrammingHardProduct company OA
What is printed?
What is printed?
void conv(int n, int b) {
if (n >= b) conv(n / b, b);
putchar("0123456789ABCDEF"[n % b]);
}
int main(void) {
conv(255, 16); putchar(' '); conv(100, 7);
}- A. FF 202
- B. F 202
- C. FF 202 0
- D. FF 151
Correct answer: A. FF 202
The recursion prints the higher digits first. 255 = 15·16 + 15, so FF. 100 = 2·49 + 0·7 + 2, so 202 in base 7. Indexing a string literal directly is legal and picks the digit character.
More C Programming questions
- A single C source file contains these three lines at file scope. What happens? c int x; int x; int x = 5;
- Assume 4-byte int, 8-byte double and natural alignment. What is printed? c struct T { double d; int i; }; struct T arr[3]; printf("%td"…
- What is printed? c int len(const char s) { return s ? 1 + len(s + 1) : 0; } int cnt(const char s, char c) { return !s ? 0 : (s == c) +…
- What is printed? c int dr(int n) { return n < 10 ? n : dr(n / 10 + n % 10); } int main(void) { printf("%d %d", dr(9875), dr(99999)); }
- What is printed? c unsigned x = 0xF0F0; x = x - ((x >> 1) & 0x5555); x = (x & 0x3333) + ((x >> 2) & 0x3333); x = (x + (x >> 4)) & 0x0F0F…
- What is printed? c struct N { int v, next; } t[] = {{10, 2}, {20, -1}, {30, 4}, {40, 1}, {50, 1}}; int s = 0; for (int i = 0; i != -1; i =…