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

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

1 CSC 1520 Computer Principles and C++ Programming C++ Basics (Part II) Fall, 2009

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

View Full Document
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

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

View Full Document
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 0 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.

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

View Full Document
6 3. Operator Precedence & Associativity How should we evaluate the following expression?
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/26/2009 for the course FINANCE FIN4110 taught by Professor Zhanghua during the Spring '09 term at CUHK.

### Page1 / 21

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

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

View Full Document
Ask a homework question - tutors are online