lec02-cpp_basics_part2

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

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

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 2)
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
5 Exercise Evaluate the following expressions 10 + -3 - 4 20 % 3 2 % 9 30 / 20 / 2 10 * 2 + 4 * 3
Background image of page 5

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

View Full Document Right Arrow Icon
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.
Background image of page 6
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.
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
Image of page 9
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 Right Arrow Icon
Ask a homework question - tutors are online