Multiple choice

What would be the output of the following?

main() { int val1=1234; int val2=01234; printf(%d %d,val1,val2); }

  1. 1234 1234

  2. 1234 01234

  3. 1234 668

  4. 1234 688

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In C, numbers starting with 0 are octal (base-8). So 01234 is octal, not decimal. Converting 01234 from octal to decimal: 1*8^3 + 2*8^2 + 3*8 + 4 = 512 + 128 + 24 + 4 = 668. Therefore, printf outputs: 1234 668.