printf


return to main index


#include <stdio.h>


The function printf() outputs text (generally) to the console - via a stream known as stdout (standard output).

The characters responsible for formatting the output text are shown in purple.

int     counter = 4;
double  x_coord = 0.123;
char    text[] = { "hello" };
char    c = 'A';

  
printf("simple message text\n");
printf("counter is %d\n", counter);
printf("x_coord with trailing zero's is %f\n", x_coord);
printf("x_coord to 3 decimal places is %1.3f\n", x_coord);
printf("text without quotations %s\n", text);
printf("text with embedded quotations \"%s\"\n", text);
printf("multiple items %d and %f\n", counter, x_coord);
printf("a single character %c\n", c);


formatting - short summary

\n
\t
\"
%d
%f
%1.3f

%s
%c
newline
tab space
quotation
placeholder for an integer value
placeholder for a floating point value
at least one character to the left and three
characters to the right of the decimal dot
placeholder for a character array ie. a string
placeholder for a single character ie. char