1 / 9

Chapter 7

Chapter 7. Expression Assignment Statements. Expressions. Syntax & Semantics of the expression. Arithmetic Expressions: Consist of operators , operands , parentheses , and function calls . Operators : Unary : meaning they have single operand . Ex: i ++

braima
Download Presentation

Chapter 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 7 Expression Assignment Statements

  2. Expressions • Syntax & Semantics of the expression. • Arithmetic Expressions: • Consist of operators, operands, parentheses, and function calls. • Operators: • Unary: meaning they have single operand. • Ex: i++ • Binary: meaning they have two operands.

  3. Expressions • Operator Evaluation Order: • Precedence • Associativity • Parentheses • Conditional Expressions

  4. Expressions • Precedence: • *, / • +,- Consider the following expression: Where: a =5 b= 10 c=2. a + b * c Solution: =5+10*2 =5+20 =25

  5. Expressions • Associativity: Consider the following expression: Where: a =5 b= 10 c=2 d=3 a + b - c – d Solution: =5+10-2-3 =15-2-3 =13-3 =10 a + c * d – b =5+2*3-10 =5+6-10 =11-10 =1

  6. Expressions • Parentheses: Consider the following expression: Where: a =5 b= 10 c=2 d=3 a + c * d – b (a + c) * (d – b) (5+3)*(3-10) (8)*(-7) -54

  7. Expressions • Conditional Statements: If ( count == 10 ) cout << “ Hello “;

  8. Assignment Statements • Simple assignment: <target Variable> <assignment operator> <expression> Area = tall * width 2. Compound assignment: a = a + b is equivalent to a+=b

  9. Assignment Statements 3. Unary assignment: Sum = count

More Related