← 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;
}
- A.0021
- B.2100
- C.21
- 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 →