Sams Teach Yourself C in 21 Days

(singke) #1

Statements ............................................................................................................


Astatementis a complete instruction that directs the computer to carry out some
task. In C, statements are usually written one per line, although some statements
span multiple lines. C statements always end with a semicolon (except for preprocessor
directives such as #defineand#include, which are discussed on Day 21, “Advanced
Compiler Use”). You’ve already been introduced to some of C’s statement types. For
example:
x = 2 + 3;
is an assignment statement. It instructs the computer to add 3 to 2 and assign the result to
the variable x. Other types of statements will be introduced as needed throughout this
book.

The Impact of Whitespace on Statements ......................................................


The term white spacerefers to spaces, horizontal tabs, vertical tabs, and blank
lines in your source code. The C compiler isn’t sensitive to white space. When
the compiler reads a statement in your source code, it looks for the characters in the
statement and for the terminating semicolon, but it ignores white space. Thus, the state-
ment
x=2+3;
is equivalent to this statement:
x = 2 + 3;
It is also equivalent to this:
x =
2
+
3 ;
This gives you a great deal of flexibility in formatting your source code. You shouldn’t
use formatting like the previous example. Statements should be entered one per line with
a standardized scheme for spacing around variables and operators. If you follow the for-
matting conventions used in this book, you should be in good shape. As you become
more experienced, you might discover that you prefer slight variations. The point is to
keep your source code readable.
The rule that C doesn’t care about white space has one exception. Within literal string
constants, tabs and spaces aren’t ignored; they are considered part of the string. A string

60 Day 4

NEWTERM

NEWTERM

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

Free download pdf