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);
}
  1. A. FF 202
  2. B. F 202
  3. C. FF 202 0
  4. 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

Exams that ask this topic