lec02-cpp_basics_part2

# lec02-cpp_basics_part2 - CSC 1111 Introduction to Computing...

This preview shows pages 1–9. Sign up to view the full content.

1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 2)

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

View Full Document
2 Outlines Operators Arithmetic Operators Operator Precedence and Associativity Expressions Different Forms of Assignment Operators Increment and Decrement Operators Swapping Values of Two Variables Simple Input
3 Operators Operators – symbols that represent operations Allow us to manipulate data in the program e.g.: variableA = 40 + 20; cout << "A"; Operand – input to an operator Binary operators – operators with 2 operands e.g.: 40 + 20 Unary operators – operators with 1 operands e.g.: - 5

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

View Full Document
4 Arithmetic Operators Operators Description Examples + Addition 10 + 3 13 - Subtraction 10 - 5 5 * Multiplication 2.2 * 2.0 4.4 / Integer division or Floating point number division 10 / 4 2 10.0 / 4.0 2.5 % Modulus (yields the remainder of division); can only be applied to integers 10 % 5 0 7 % 3 1
5 Exercise Evaluate the following expressions 10 + -3 - 4 20 % 3 2 % 9 30 / 20 / 2 10 * 2 + 4 * 3

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

View Full Document
6 Expressions with Multiple Operators Evaluate 2 - 25 / 10 + 33 % 10 * 2 In what order should the operators be applied? Look up the precedence and associativity of the operators.
7 Among different operators , operator precedence tells us which operator(s) should be applied first. Among operators with the same precedence , operator associativity tells us whether the left-most or the right-most operator should be applied first.

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

View Full Document
Operator Associativity Precedence () ++ (postfix) -- (postfix) left to right Highest + (unary) - (unary) ++ (prefix) -- (prefix) right to left * / % left to right + - left to right = += -= *= /= etc. right to left Lowest Operators at the same level have the same precedence. - a * b - c
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 27

lec02-cpp_basics_part2 - CSC 1111 Introduction to Computing...

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

View Full Document
Ask a homework question - tutors are online