What is the output of the following code written in C? void main() {…
2021
What is the output of the following code written in C?
void main()
{
printf("%d%d%d", 62, 062, 0x62);
}
- A.
506298
- B.
629850
- C.
625098
- D.
986250
Attempted by 1177 students.
Show answer & explanation
Correct answer: C
The code uses printf with three integer arguments formatted as %d.
First argument: 62 is a decimal integer, so it prints as 62.
Second argument: 062 starts with 0, indicating octal. 6*8 + 2 = 50.
Third argument: 0x62 indicates hexadecimal. 6*16 + 2 = 98.
The format string %d%d%d prints them consecutively, resulting in 625098.