3.4. Quick Explanation of printf()
You may have noticed two characters near the end of our
printf() statements \n. These
don't get displayed to the screen, they are the notation
printf() uses to represent "newline".
'\' is the c escape character
when it is encountered within quotes the following character usually
has a special meaning. Another example is \t which
is used to represent a TAB.
Another special character that printf()
looks out for is '%', this tells it to look at the
next few characters and be ready to replace them with the value of a
variable. %d is the character sequence that
represents a variable of type int to be displayed
using the decimal counting system (0 .. 9). For every
%d in the format string you must tell
printf() what variable you want it replaced with.
Here's some more use of printf() in code:
Example 3-4. more_printf.c
int
main()
{
int one = 1;
int two = 2;
int three = 4; /* the values are unimportant here */
printf( "one ==\t%d\ntwo ==\t%d\nthree ==\t%d\n", one, two, three );
return 0;
}