Chp4 - C+ PROGRAMMING Chapter 4 Expressions and Statements...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 4 Expressions and Statements Statements Whitespace Blocks and Compound Statements Expressions Listing 4.1. Evaluating complex expressions . Operators Assignment Operator , Mathematical Operators Listing 4.2. A demonstration of subtraction and integer overflow . Integer Division and Modulus Combining the Assignment and Mathematical Operators Increment and Decrement Prefix and Postfix Listing 4.3. A demonstration of prefix and postfix operators . Precedence Nesting Parentheses The Nature of Truth Relational Operators The if Statement Listing 4.4. A demonstration of branching based on relational operators . Indentation Styles else Listing 4.5. Demonstrating the else keyword . The if Statement Advanced if Statements Listing 4.6. A complex, nested if statement . Using Braces in Nested if Statements Listing 4.7. A demonstration of why braces help clarify which else statement goes with which if statement. Listing 4.8. A demonstration of the proper use of braces with an if statement . Logical Operators Logical AND , Logical OR , & Logical NOT Relational Precedence More About Truth and Falsehood Conditional (Ternary) Operator Listing 4.9. A demonstration of the conditional operator . Summary Quiz , Exercises
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Chapter 4 Expressions and Statements At its heart, a program is a set of commands executed in sequence. The power in a program comes from its capability to execute one or another set of commands, based on whether a particular condition is true or false. ToChapter you will learn What statements are. What blocks are. What expressions are. How to branch your code based on conditions. What truth is, and how to act on it. Statements In C++ a statement controls the sequence of execution, evaluates an expression, or does nothing (the null statement). All C++ statements end with a semicolon, even the null statement, which is just the semicolon and nothing else. One of the most common statements is the following assignment statement: x = a + b; Unlike in algebra, this statement does not mean that x equals a+b . This is read, "Assign the value of the sum of a and b to x ," or "Assign to x , a+b ." Even though this statement is doing two things, it is one statement and thus has one semicolon. The assignment operator assigns whatever is on the right side of the equal sign to whatever is on the left side. New Term: A null statement is a statement that does nothing. Whitespace Whitespace (tabs, spaces, and newlines) is generally ignored in statements. The assignment statement previously discussed could be written as x=a+b; or as x = a + b ; Although this last variation is perfectly legal, it is also perfectly foolish. Whitespace can be used to make your programs more readable and easier to maintain, or it can be used to create horrific and indecipherable code. In this, as in all things, C++ provides the power; you supply the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

Chp4 - C+ PROGRAMMING Chapter 4 Expressions and Statements...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online