Prefix 0
to the output value when used with the octal conversion specifier
o.
Prefix 0x or
0X to the
output value when used with the hexadecimal conversion specifiers
x or
X.
Force a decimal points for a floating-point number printed with
e,
E,
f,
g,
or G that
does not contain a fractional part. (Normally the decimal
point is only printed if a digit follows it). For g
and G
specifiers, trailing zeros are not eliminated.

Output:

5.10 Printing Literals
And Escape Sequences

Various control
characters, such as newline and tab, must be represented by escape sequences.

An escape sequence
is represented by a backslash (\) followed by a particular escape character.

Table 5.5 summarizes
all the escape sequences and the actions they cause.

Escape sequence

Description

\’

Output the single quote (’)
character.

\"

Output the double quote (")
character.

\?

Output the question mark (?)
character.

\\

Output the backslash (\)
character.

\a

Cause an audible (bell) or visual alert.

\b

Move the cursor back one position on
the current line.

\f

Move the cursor to the start of the
next logical page.

\n

Move the cursor to the beginning of
the next line.

\r

Move the cursor to the beginning of
the current line.

\t

Move the cursor to the next horizontal
tab position.

\v

Move the cursor to the next vertical
tab position.

Table 5.5: Escape sequences

Other printf()
family that you might find somewhere, sometime is listed in the following
Table. It is important to note that some of these are not part of
the standard library but are widely available. You have to check your
compiler.

In newer compiler
there are new,
secure version of these family and other string related function that
can be recognized by the _s suffix such
as printf_s().

Function

Description &
Prototype

printf()

Prints output on the standard output
stream stdout. Include stdio.h.

int printf(const char *restrictformat,
...);

fprintf()

Prints output on the named output
stream. Include stdio.h.

int fprintf(FILE *restrictstream,
const char *restrictformat,
...);

sprintf()

Prints output followed by the null byte,
'\0',
in consecutive bytes starting at *s;
it is the user's responsibility to ensure that enough space is available.
Include stdio.h.

int sprintf(char *restricts,
const char *restrictformat,
...);

snprintf()

Prints into a string with length checking.
Equivalent to sprintf(),
with the addition of the n
argument which states the size of the buffer referred to by
s.
If n is zero, nothing shall be written and s
may be a null pointer. Otherwise, output bytes beyond the n-1st shall be discarded instead
of being written to the array, and a null byte is written at the
end of the bytes actually written into the array. Include
stdio.h.

Print to a FILE
stream from a va_arg
structure. Equivalent to printf(),
except that instead of being called with a variable number of arguments,
they are called with an argument list as defined by stdarg.h.
Include stdarg.h and
stdio.h.

Prints to ‘stdout’ from a va_arg
structure. Equivalent to fprintf()
respectively, except that instead of being called with a variable
number of arguments, they are called with an argument list as defined
by stdarg.h.
Include stdarg.h and
stdio.h.

int vprintf(const char *restrictformat,
va_listap);

vsprintf()

Prints to a string from a va_arg
structure. Equivalent to sprintf()
respectively, except that instead of being called with a variable
number of arguments, they are called with an argument list as defined
by stdarg.h.
Include stdarg.h and
stdio.h.

int vsprintf(char *restricts,
const char *restrictformat,
va_listap);

vsnprintf()

Prints to a string with length checking
from a va_arg
structure. Equivalent to snprintf(),
except that instead of being called with a variable number of arguments,
they are called with an argument list as defined by stdarg.h.
Include stdarg.h and
stdio.h.