the standard output to your screen unless you know enough to route the output
elsewhere. Most of the time, you can ignore this standard output device stuff because
you’ll almost always want output to go to the screen. Other C functions you will learn
about later route output to your printer and disk drives.
Note
You might be wondering why some of the words in the format appear in italics. It’s
because they’re placeholders. A placeholder is a name, symbol, or formula that you
supply. Placeholders are italicized in the format of functions and commands to let you
know that you should substitute something at that place in the command.
Here is an example of a printf():
Click here to view code image
printf("My favorite number is %d", 7); // Prints My favorite number
// is 7
Because every string in C must be enclosed in quotation marks (as mentioned in Chapter 2), the
controlString must be in quotation marks. Anything following the controlString is
optional and is determined by the values you want printed.
Note
Every C command and function needs a semicolon (;) after it to let C know that the
line is finished. Braces and the first lines of functions don’t need semicolons because
nothing is executing on those lines. All statements with printf() should end in a
semicolon. You won’t see semicolons after main(), however, because you don’t
explicitly tell C to execute main(). You do, however, tell C to execute printf()
and many other functions. As you learn more about C, you’ll learn more about
semicolon placement.
Printing Strings
String messages are the easiest type of data to print with printf(). You have to enclose only the
string in quotation marks. The following printf() prints a message on the screen:
Click here to view code image
printf("You are on your way to C mastery");
The message You are on your way to C mastery appears onscreen when the computer
executes this statement.