From the course: C: Data Structures, Pointers, and File Systems

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using printf() placeholders

Using printf() placeholders - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

Using printf() placeholders

- [Instructor] Perhaps the best way to understand the various width options for the printf functions placeholders, is to run some samples in code. This code outputs integer value one, two, three, using a clutch of different width formats. First at line eight comes the default placeholder %d. No width is specified. Lines 10 through 12 use eight as the width, and increase the value displayed for each printf statement. So line 11 it's a*10, line 12 it's a*100. Lines 14 through 16 duplicate these values, but left justified the output. See the minus sign at lines 14 through 16? Finally, a zero is added to the widths specifier at lines 18 through 20. Which pads zero's to the left of the number, filling the width of eight places. Build and run. Behold, the effect of all the conversion specifications on the values. In this exercise file, you see the %f placeholder with some width and truncation options. Line eight specifies no width. Line 10 specifies a width of 15 characters. Line 12…

Contents