Minimum Field Width Specifier in printf() - C Language Basics

C examples for Language Basics:printf

Introduction

An integer between % and the format code sets a minimum field width.

The padding ensures that it reaches a certain minimum length.

If the value is longer than that minimum, it will still be printed in full.

The default padding is done with spaces.

If you wish to pad with 0's, place a 0 before the field width specifier.

For example, %05d will pad a number of less than five digits with 0's so that its total length is five.

The following program demonstrates the minimum field width specifier:

Demo Code

#include <stdio.h>

int main(void)
{
   double item;//from   w  w w.j  a va2s  .c  o m

   item = 10.12304;


   printf("%f\n", item);
   printf("%10f\n", item);
   printf("%012f\n", item);

   return 0;

}

Result


Related Tutorials