Objectives
-
Upload
lysandra-bullock -
Category
Documents
-
view
14 -
download
0
description
Transcript of Objectives
![Page 1: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/1.jpg)
Computer Science: A Structured Programming Approach Using C 1
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 3Chapter 3 Structure of a C ProgramStructure of a C Program
![Page 2: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/2.jpg)
Computer Science: A Structured Programming Approach Using C 2
3-1 Expressions
An expression is a sequence of operands and operators An expression is a sequence of operands and operators that reduces to a single value. Expressions can be that reduces to a single value. Expressions can be simple or complex. An operator is a syntactical token simple or complex. An operator is a syntactical token that requires an action be taken. An operand is an that requires an action be taken. An operand is an object on which an operation is performed; it receives object on which an operation is performed; it receives an operator’s action.an operator’s action.
Primary ExpressionsPostfix ExpressionsPrefix ExpressionsUnary ExpressionsBinary Expressions
Topics discussed in this section:Topics discussed in this section:
![Page 3: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/3.jpg)
Computer Science: A Structured Programming Approach Using C 3
An expression always reduces to a single value.
NoteNote
![Page 4: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/4.jpg)
Computer Science: A Structured Programming Approach Using C 4
FIGURE 3-1 Expression Categories
![Page 5: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/5.jpg)
Computer Science: A Structured Programming Approach Using C 5
FIGURE 3-2 Postfix Expressions
![Page 6: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/6.jpg)
Computer Science: A Structured Programming Approach Using C 6
(a++) has the same effect as (a = a + 1)
NoteNote
![Page 7: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/7.jpg)
Computer Science: A Structured Programming Approach Using C 7
FIGURE 3-3 Result of Postfix a++
![Page 8: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/8.jpg)
Computer Science: A Structured Programming Approach Using C 8
The operand in a postfix expression must be a variable.
NoteNote
![Page 9: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/9.jpg)
Computer Science: A Structured Programming Approach Using C 9
PROGRAM 3-1 Demonstrate Postfix Increment
![Page 10: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/10.jpg)
Computer Science: A Structured Programming Approach Using C 10
PROGRAM 3-1 Demonstrate Postfix Increment (continued)
![Page 11: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/11.jpg)
Computer Science: A Structured Programming Approach Using C 11
FIGURE 3-4 Prefix Expression
![Page 12: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/12.jpg)
Computer Science: A Structured Programming Approach Using C 12
The operand of a prefix expression must be a variable.
NoteNote
![Page 13: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/13.jpg)
Computer Science: A Structured Programming Approach Using C 13
FIGURE 3-5 Result of Prefix ++a
![Page 14: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/14.jpg)
Computer Science: A Structured Programming Approach Using C 14
(++a) has the same effect as (a = a + 1)
NoteNote
![Page 15: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/15.jpg)
Computer Science: A Structured Programming Approach Using C 15
PROGRAM 3-2 Demonstrate Prefix Increment
![Page 16: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/16.jpg)
Computer Science: A Structured Programming Approach Using C 16
PROGRAM 3-2 Demonstrate Prefix Increment (continued)
![Page 17: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/17.jpg)
Computer Science: A Structured Programming Approach Using C 17
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 incrementtakes place before the expression is evaluated.
NoteNote
![Page 18: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/18.jpg)
Computer Science: A Structured Programming Approach Using C 18
FIGURE 3-6 Unary Expressions
![Page 19: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/19.jpg)
Computer Science: A Structured Programming Approach Using C 19
Table 3-1 Examples of Unary Plus And Minus Expressions
![Page 20: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/20.jpg)
Computer Science: A Structured Programming Approach Using C 20
FIGURE 3-7 Binary Expressions
![Page 21: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/21.jpg)
Computer Science: A Structured Programming Approach Using C 21
Both operands of the modulo operator (%) must be integral types.
NoteNote
![Page 22: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/22.jpg)
Computer Science: A Structured Programming Approach Using C 22
PROGRAM 3-3 Binary Expressions
![Page 23: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/23.jpg)
Computer Science: A Structured Programming Approach Using C 23
PROGRAM 3-3 Binary Expressions (continued)
![Page 24: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/24.jpg)
Computer Science: A Structured Programming Approach Using C 24
PROGRAM 3-3 Binary Expressions (continued)
![Page 25: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/25.jpg)
Computer Science: A Structured Programming Approach Using C 25
The left operand in an assignment expression must be a single variable.
NoteNote
![Page 26: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/26.jpg)
Computer Science: A Structured Programming Approach Using C 26
Table 3-2 Expansion of Compound Expressions
![Page 27: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/27.jpg)
Computer Science: A Structured Programming Approach Using C 27
PROGRAM 3-4 Demonstration of Compound Assignments
![Page 28: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/28.jpg)
Computer Science: A Structured Programming Approach Using C 28
PROGRAM 3-4 Demonstration of Compound Assignments
![Page 29: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/29.jpg)
Computer Science: A Structured Programming Approach Using C 29
PROGRAM 3-4 Demonstration of Compound Assignments
![Page 30: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/30.jpg)
Computer Science: A Structured Programming Approach Using C 30
3-2 Precedence and Associativity
Precedence is used to determine the order in which Precedence is used to determine the order in which different operators in a complex expression are different operators in a complex expression are evaluated. Associativity is used to determine the order evaluated. Associativity is used to determine the order in which operators with the same precedence are in which operators with the same precedence are evaluated in a complex expression. evaluated in a complex expression.
PrecedenceAssociativity
Topics discussed in this section:Topics discussed in this section:
![Page 31: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/31.jpg)
Computer Science: A Structured Programming Approach Using C 31
PROGRAM 3-5 Precedence
![Page 32: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/32.jpg)
Computer Science: A Structured Programming Approach Using C 32
PROGRAM 3-5 Precedence
![Page 33: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/33.jpg)
Computer Science: A Structured Programming Approach Using C 33
![Page 34: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/34.jpg)
Computer Science: A Structured Programming Approach Using C 34
FIGURE 3-8 Left-to-Right Associativity
![Page 35: Objectives](https://reader035.fdocuments.in/reader035/viewer/2022081515/56812cfc550346895d91ce65/html5/thumbnails/35.jpg)
Computer Science: A Structured Programming Approach Using C 35
FIGURE 3-9 Right-to-Left Associativity