Multiple choice

If the declaration is float x = 123.456, then the statement printf(“%7f %7.1f “,x,x) will print

  1. 123.456000 & 123.5

  2. 123.456 & 123.4

  3. 123.4560000 & 123.5

  4. 123.456000 & 123.0

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

%%7f prints a float with minimum width 7 and default 6 decimal places, giving '123.456000' (9 characters, exceeds width). %%7.1f prints with 1 decimal place and minimum width 7, giving ' 123.5' (padded with 2 spaces). The space in the format separates the two outputs.