Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.

Similar presentations


Presentation on theme: "Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand."— Presentation transcript:

1 Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand the rules of precedence and associativity in evaluating expressions ❏ To understand the result of side effects in expression evaluation ❏ To be able to predict the results when an expression is evaluated ❏ To understand implicit and explicit type conversion ❏ To understand and use the first four statement types: null, expression, return, and compound Chapter 3 Chapter 3 Structure of a C Program Structure of a C Program

2 Computer Science: A Structured Programming Approach Using C2 3-1 Expressions An expression is a sequence of operands and operators that reduces to a single value. Expressions can be simple or complex. An operator is a syntactical token that requires an action be taken. An operand is an object on which an operation is performed; it receives an operator’s action. Primary Expressions Postfix Expressions Prefix Expressions Unary Expressions Binary Expressions Topics discussed in this section:

3 Computer Science: A Structured Programming Approach Using C3 An expression always reduces to a single value. Note

4 Computer Science: A Structured Programming Approach Using C4 FIGURE 3-1 Expression Categories

5 Computer Science: A Structured Programming Approach Using C5 FIGURE 3-2 Postfix Expressions

6 Computer Science: A Structured Programming Approach Using C6 (a++) has the same effect as (a = a + 1) Note

7 Computer Science: A Structured Programming Approach Using C7 FIGURE 3-3 Result of Postfix a++

8 Computer Science: A Structured Programming Approach Using C8 The operand in a postfix expression must be a variable. Note

9 Computer Science: A Structured Programming Approach Using C9 PROGRAM 3-1Demonstrate Postfix Increment

10 Computer Science: A Structured Programming Approach Using C10 PROGRAM 3-1Demonstrate Postfix Increment (continued)

11 Computer Science: A Structured Programming Approach Using C11 FIGURE 3-4 Prefix Expression

12 Computer Science: A Structured Programming Approach Using C12 The operand of a prefix expression must be a variable. Note

13 Computer Science: A Structured Programming Approach Using C13 FIGURE 3-5 Result of Prefix ++a

14 Computer Science: A Structured Programming Approach Using C14 (++a) has the same effect as (a = a + 1) Note

15 Computer Science: A Structured Programming Approach Using C15 PROGRAM 3-2Demonstrate Prefix Increment

16 Computer Science: A Structured Programming Approach Using C16 PROGRAM 3-2Demonstrate Prefix Increment (continued)

17 Computer Science: A Structured Programming Approach Using C17 If ++ is after the operand, as in a++, the increment takes place after the expression is evaluated. If ++ is before the operand, as in ++a, the increment takes place before the expression is evaluated. Note

18 Computer Science: A Structured Programming Approach Using C18 FIGURE 3-6 Unary Expressions

19 Computer Science: A Structured Programming Approach Using C19 Table 3-1Examples of Unary Plus And Minus Expressions

20 Computer Science: A Structured Programming Approach Using C20 FIGURE 3-7 Binary Expressions

21 Computer Science: A Structured Programming Approach Using C21 Both operands of the modulo operator (%) must be integral types. Note

22 Computer Science: A Structured Programming Approach Using C22 PROGRAM 3-3Binary Expressions

23 Computer Science: A Structured Programming Approach Using C23 PROGRAM 3-3 Binary Expressions (continued)

24 Computer Science: A Structured Programming Approach Using C24 PROGRAM 3-3Binary Expressions (continued)

25 Computer Science: A Structured Programming Approach Using C25 The left operand in an assignment expression must be a single variable. Note

26 Computer Science: A Structured Programming Approach Using C26 Table 3-2Expansion of Compound Expressions

27 Computer Science: A Structured Programming Approach Using C27 PROGRAM 3-4Demonstration of Compound Assignments

28 Computer Science: A Structured Programming Approach Using C28 PROGRAM 3-4Demonstration of Compound Assignments

29 Computer Science: A Structured Programming Approach Using C29 PROGRAM 3-4Demonstration of Compound Assignments

30 Computer Science: A Structured Programming Approach Using C30 3-2 Precedence and Associativity Precedence is used to determine the order in which different operators in a complex expression are evaluated. Associativity is used to determine the order in which operators with the same precedence are evaluated in a complex expression. Precedence Associativity Topics discussed in this section:

31 Computer Science: A Structured Programming Approach Using C31 PROGRAM 3-5Precedence

32 Computer Science: A Structured Programming Approach Using C32 PROGRAM 3-5Precedence

33 Computer Science: A Structured Programming Approach Using C33

34 Computer Science: A Structured Programming Approach Using C34 FIGURE 3-8 Left-to-Right Associativity

35 Computer Science: A Structured Programming Approach Using C35 FIGURE 3-9 Right-to-Left Associativity


Download ppt "Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand."

Similar presentations


Ads by Google