Multiple choice

Which one of the following printf() format specifiers indicates to print a double value in decimal notation, left aligned in a 30-character field, to four (4) digits of precision?

  1. %- 30.4e

  2. %4.30e

  3. %-4.30f

  4. %-30.4f

  5. %#30.4f

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

The format specifier %-30.4f means: % begins the format, - left-aligns the output, 30 sets minimum field width, .4 specifies 4 decimal places, and f indicates decimal (not exponential) notation. This is the correct combination for a double value, left-aligned in a 30-character field with 4 digits of precision. The 'e' specifier would give exponential notation, and the order of width and precision matters.