Sams Teach Yourself C in 21 Days

(singke) #1
The Pieces of a C Program: Statements, Expressions, and Operators 61

4


is a series of characters. Literal string constants are strings that are enclosed within
quotes and interpreted literally by the compiler, space for space. An example of a literal
string is
“How now brown cow”
This literal string is different from the following:
“How now brown cow”
The difference is a result of the additional spaces. With a literal string, C keeps track of
the white space.
Although it’s extremely bad form, the following is legal code in C:
printf(
“Hello, world!”
);
This, however, is not legal:
printf(“Hello,
world!”);
To break a literal string constant line, you must use the backslash character (\) just
before the break. Thus, the following is legal:
printf(“Hello,\
world!”);

Creating a Null Statements ..............................................................................


If you place a semicolon by itself on a line, you create a null statement. A null
statement is one that doesn’t perform any action. This is perfectly legal in C.
Later in this book, you will learn how the null statement can be useful.

Working with Compound Statements ............................................................


Acompound statement, also called a block,is a group of two or more C state-
ments enclosed in braces. Here’s an example of a block:
{
printf(“Hello, “);
printf(“world!”);
}
In C, a block can be used anywhere a single statement can be used. Many examples of
this appear throughout this book. Note that the enclosing braces can be positioned in dif-
ferent ways. The following is equivalent to the preceding example:
{printf(“Hello, “);
printf(“world!”);}

NEWTERM

NEWTERM

07 448201x-CH04 8/13/02 11:14 AM Page 61

Free download pdf