C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1
Column A Column B Column C
My Computer's Beep Sounds Like This:!
"Let's fix that typo and then show the backslash character \" she
said

Note

You should understand a few things about the previous listing. First, you must always
place #include <stdio.h> at the beginning of all programs that use the
printf() function—it is defined in stdio.h, so if you fail to remember that line
of code, you will get a compiler error because your program will not understand how
to execute printf(). Also, different C/C++ compilers might produce a different
number of tabbed spaces for the \t escape sequence. Finally, it is important to note
that using the \b escape sequence overwrites anything that was there. That’s why the
'z' does not appear in the output, but the 's' does.

Conversion Characters


When you print numbers and characters, you must tell C exactly how to print them. You indicate the
format of numbers with conversion characters. Table 4.2 lists a few of C’s most-used conversion
characters.


TABLE 4.2 Conversion Characters

When you want to print a value inside a string, insert the appropriate conversion characters in the
controlString. Then to the right of the controlString, list the value you want to be printed.
Figure 4.1 is an example of how a printf() can print three numbers—an integer, a floating-point
value, and another integer.

Free download pdf