Printing integers with the 0 (zero) flag fills in leading zeros in C programming

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Printing integers with the 0 (zero) flag fills in leading zeros in C programming

To show: How to display integers with the 0 (zero) flag fills in leading zeros using printf() C function

 

 

// Printing integers with 0 (zero) flag fills in leading zeros

#include <stdio.h>

 

int main(void)

{

printf("Printing with the 0 (zero) flag fills in leading zeros\n");

printf(" Compare the output with the source code\n");

printf("-------------------------------------------------------\n\n");

printf("%+09d\n", 762);

printf("%09d", 762);

 

printf("\n");

 

return 0;

}

 

Output example:

 

Printing with the 0 (zero) flag fills in leading zeros

Compare the output with the source code

-------------------------------------------------------

+00000762

000000762

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index