printf() Demonstration Program
#include <stdio.h>
int
main(void)
{
printf("%%|\n");
printf("\n");
printf("%c|\n", 'a');
printf("%5c|\n", 'a');
printf("%-5c|\n", 'a');
printf("\n");
printf("%d|\n", 123456);
printf("%5d|\n", 123456);
printf("%6d|\n", 123456);
printf("%6d|\n", 1);
printf("---\n");
printf("%4.2d|\n", 123456);
printf("%6.2d|\n", 123456);
printf("%6.2d|\n", 1);
printf("---\n");
printf("%06d|\n", 123456);
printf("%-6d|\n", 123456);
printf("% 6d|\n", 123456);
printf("%+6d|\n", 123456);
printf("---\n");
printf("%08d|\n", 123456);
printf("%-8d|\n", 123456);
printf("% 8d|\n", 123456);
printf("%+8d|\n", 123456);
printf("---\n");
printf("%-6.2d|\n", 123456);
printf("% 6.2d|\n", 123456);
printf("%+6.2d|\n", 123456);
printf("\n");
printf("%i|\n", 123456);
printf("%5i|\n", 123456);
printf("%6i|\n", 123456);
printf("%6i|\n", 1);
printf("\n");
printf("%o|\n", 123456);
printf("%4o|\n", 123456);
printf("%5o|\n", 123456);
printf("---\n");
printf("%4.2o|\n", 123456);
printf("%5.2o|\n", 123456);
printf("---\n");
printf("%#5o|\n", 123456);
printf("%05o|\n", 123456);
printf("%-5o|\n", 123456);
printf("---\n");
printf("%#8o|\n", 123456);
printf("%08o|\n", 123456);
printf("%-8o|\n", 123456);
printf("---\n");
printf("%-5.2o|\n", 123456);
printf("\n");
printf("%x|\n", 123456);
printf("%4x|\n", 123456);
printf("%5x|\n", 123456);
printf("---\n");
printf("%X|\n", 123456);
printf("---\n");
printf("%4.2x|\n", 123456);
printf("%5.2x|\n", 123456);
printf("---\n");
printf("%#5x|\n", 123456);
printf("%05x|\n", 123456);
printf("%-5x|\n", 123456);
printf("---\n");
printf("%#8x|\n", 123456);
printf("%08x|\n", 123456);
printf("%-8x|\n", 123456);
printf("---\n");
printf("%#8X|\n", 123456);
printf("%08X|\n", 123456);
printf("%-8X|\n", 123456);
printf("---\n");
printf("%-5.2x|\n", 123456);
printf("\n");
printf("%e|\n", 12345.6789);
printf("%4e|\n", 12345.6789);
printf("%5e|\n", 12345.6789);
printf("---\n");
printf("%E|\n", 12345.6789);
printf("---\n");
printf("%4.2e|\n", 12345.6789);
printf("%5.2e|\n", 12345.6789);
printf("%4.2E|\n", 12345.6789);
printf("%5.2E|\n", 12345.6789);
printf("---\n");
printf("%#5e|\n", 12345.6789);
printf("%05e|\n", 12345.6789);
printf("%-5e|\n", 12345.6789);
printf("% 5e|\n", 12345.6789);
printf("%+5e|\n", 12345.6789);
printf("---\n");
printf("%#8e|\n", 12345.6789);
printf("%08e|\n", 12345.6789);
printf("%-8e|\n", 12345.6789);
printf("% 8e|\n", 12345.6789);
printf("%+8e|\n", 12345.6789);
printf("---\n");
printf("%#8E|\n", 12345.6789);
printf("%08E|\n", 12345.6789);
printf("%-8E|\n", 12345.6789);
printf("% 8E|\n", 12345.6789);
printf("%+8E|\n", 12345.6789);
printf("---\n");
printf("%#5.2e|\n", 12345.6789);
printf("%05.2e|\n", 12345.6789);
printf("%-5.2e|\n", 12345.6789);
printf("% 5.2e|\n", 12345.6789);
printf("%+5.2e|\n", 12345.6789);
printf("\n");
printf("%f|\n", 12345.6789);
printf("%4f|\n", 12345.6789);
printf("%5f|\n", 12345.6789);
printf("---\n");
printf("%4.2f|\n", 12345.6789);
printf("%5.2f|\n", 12345.6789);
printf("---\n");
printf("%#5f|\n", 12345.6789);
printf("%05f|\n", 12345.6789);
printf("%-5f|\n", 12345.6789);
printf("% 5f|\n", 12345.6789);
printf("%+5f|\n", 12345.6789);
printf("---\n");
printf("%#8f|\n", 12345.6789);
printf("%08f|\n", 12345.6789);
printf("%-8f|\n", 12345.6789);
printf("% 8f|\n", 12345.6789);
printf("%+8f|\n", 12345.6789);
printf("---\n");
printf("%#5.2f|\n", 12345.6789);
printf("%05.2f|\n", 12345.6789);
printf("%-5.2f|\n", 12345.6789);
printf("% 5.2f|\n", 12345.6789);
printf("%+5.2f|\n", 12345.6789);
printf("\n");
printf("%g|\n", 12345.6789);
printf("%4g|\n", 12345.6789);
printf("%5g|\n", 12345.6789);
printf("---\n");
printf("%G|\n", 12345.6789);
printf("---\n");
printf("%4.2g|\n", 12345.6789);
printf("%5.2g|\n", 12345.6789);
printf("---\n");
printf("%#5g|\n", 12345.6789);
printf("%05g|\n", 12345.6789);
printf("%-5g|\n", 12345.6789);
printf("% 5g|\n", 12345.6789);
printf("%+5g|\n", 12345.6789);
printf("---\n");
printf("%#8g|\n", 12345.6789);
printf("%08g|\n", 12345.6789);
printf("%-8g|\n", 12345.6789);
printf("% 8g|\n", 12345.6789);
printf("%+8g|\n", 12345.6789);
printf("---\n");
printf("%#8G|\n", 12345.6789);
printf("%08G|\n", 12345.6789);
printf("%-8G|\n", 12345.6789);
printf("% 8G|\n", 12345.6789);
printf("%+8G|\n", 12345.6789);
printf("---\n");
printf("%#5.2g|\n", 12345.6789);
printf("%05.2g|\n", 12345.6789);
printf("%-5.2g|\n", 12345.6789);
printf("% 5.2g|\n", 12345.6789);
printf("%+5.2g|\n", 12345.6789);
printf("\n");
printf("%s|\n", "12345");
printf("%4s|\n", "12345");
printf("%5s|\n", "12345");
printf("---\n");
printf("%4.2s|\n", "12345");
printf("%5.2s|\n", "12345");
printf("---\n");
printf("%-5s|\n", "12345");
printf("---\n");
printf("%-8s|\n", "12345");
printf("---\n");
printf("%-5.2s|\n", "12345");
printf("\n");
printf("%p|\n", "12345");
printf("%4p|\n", "12345");
printf("%5p|\n", "12345");
printf("---\n");
printf("%-5p|\n", "12345");
printf("---\n");
printf("%-8p|\n", "12345");
printf("\n");
return(0);
}
You can now either see the output of this program
or
go back to the printf()
page