🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Number Programs in C: all 10 questions

Quiz: Number Programs in C · Question 2 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int n = 1200, rev = 0;
    while (n > 0) { rev = rev * 10 + n % 10; n /= 10; }
    printf("%d\n", rev);
    return 0;
}
  1. A.0021
  2. B.2100
  3. C.21
  4. D.12
Answer & explanation

Correct answer: 21

The reverse is built as 0, 0, 2, 21; leading zeros have no value in an int.

Can you get the rest right without peeking?

Take the timed Quiz: Number Programs in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →