< previous page page_60 next page >

Page 60
Summary
In this hour you learned what a statement is. You also learned that an expression is any statement that returns a value. You learned that whitespace can be used to make your program more readable, and you saw how to use the mathematical and assignment operators.
You also learned how to use the prefix and postfix operators, as well as the relational operators. You learned how to use the if statement, how to use else, and how to create complex and nested if statements.
Q&A
Q Why use unnecessary parentheses when precedence will determine which operators are acted on first?
A Although it is true that the compiler will know the precedence and that a programmer can look up the precedence order, code that is easy to understand is easier to maintain.
Q If the relational operators always return 1 or 0, why are other values considered true?
A The relational operators return 1 or 0, but every expression returns a value, and those values can also be evaluated in an if statement. Here's an example:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
if ( (x = a + b) == 35 )
This is a perfectly legal C++ statement. It evaluates to a value even if the sum of a and b is not equal to 35. Also note that x is assigned the value that is the sum of a and b in any case.
Q What effect do tabs, spaces, and new lines have on the program?
A Tabs, spaces, and new lines (known as whitespace) have no effect on the program, although whitespace can make the program easier to read.
Q Are negative numbers true or false?
A All nonzero numbers, positive and negative, are true.

 
< previous page page_60 next page >

If you like this book, buy it!