lec03 - 1 CSC 1520 Computer Principles and C++ Programming...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 CSC 1520 Computer Principles and C++ Programming C++ Basics (Part II) Fall, 2009 2 Outlines 1. Operators 2. Arithmetic Operators 3. Operator Precedence and Associativity 4. Expressions 5. Different Forms of Assignment Operators 6. Increment and Decrement Operators 7. Swapping Values of Two Variables 3 1. Operators An operator is a symbol or keyword that represents an operation. We use operators to manipulate data in the program e.g.: variableA = 40 + 20; cout << "A"; Operand input to an operator Binary operator an operator that accepts 2 operands e.g.: 40 + 20 Unary operator an operator that accepts only 1 operand e.g.: - 5 4 2. 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 a division); can only be applied to integers 10 % 5 7 % 3 1 5 2. Arithmetic Operators Exercise : evaluate the following expressions 20 % 3 2 % 9 30 / 20 / 2 10 * 2 + 4 * 3 When used as an unary operator , becomes a negation operator, which turns positive value into negative value and vice versa. e.g.:- 5 yields "negative five" + can also be used as an unary operator. 6 3. Operator Precedence & Associativity How should we evaluate the following expression?...
View Full Document

Page1 / 21

lec03 - 1 CSC 1520 Computer Principles and C++ Programming...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online