C++ lecture 4

49 8 0
C++ lecture 4

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

C++ Programming Language Lecture C++ Basics – Part II The Hashemite University Computer Engineering Department (Adapted from the textbook slides) Outline            Arithmetic operators Logical operators Assignment operator Increment and decrement operators Bitwise Operators Relational Operators ‘Size of’ operator Comma operator Operators Precedence cout and cin cascading Escape Sequences The Hashemite University Arithmetic Operators I  Arithmetic operators:        Addition + Subtraction Division / Multiplication * Modulus % Arithmetic operators are binary operators (take two operands) Result of / (division) depends on the operands types  Division Result Examples: E.g: E.g: int a= 5; int b = 2; double c = a/b; c= double a= 5; double b = 2; double c = a/b; c = 2.5 E.g: double a= 5; double b = 2; int c = a/b; c = E.g: double c = 5/2; c= E.g: double c = 5.0/2; c = 2.5 E.g: double c = 5/2.0; c = 2.5 The Hashemite University Arithmetic Operators II (1) Result = number1 / number2  Division Operator General Rules: Operand data type Operand data type Temporary result Holder data type Saved Result int int integer int integer int int integer double/float integer int double/float Floating point int integer int double/float Floating point double/float Floating point double/float int Floating point int integer double/float int Floating point double/float Floating point double/float Hashemite University double/float The Floating int integer Arithmetic Operators III       % (modulus which finds the remainder) is applied for integer values only So, 9%4 = 1, but 9%2.5  Syntax Error Operators precedence: *, %, and / have the same priority which are higher than + and – (+ and – have the same priority) double c= 5-6 * /3 %3+7/3 , c= ?? If multiple operators are combined which have the same priority you start implementation from left to right Remember that parenthesis forces priority For nested parenthesis you start with the most inner parenthesis pair For multiple parenthesis start implementation from left to right The Hashemite University Example #include int main() { int a = 9, b = 30, c = 89, d = 35, x; double e = 3, y; cout

Ngày đăng: 12/10/2021, 21:08

Mục lục

    C++ Programming Language Lecture 4 C++ Basics – Part II

    Equality and Relational Operators I

    Equality and Relational Operators II

    Confusing Equality (==) and Assignment (=) Operators I

    Confusing Equality (==) and Assignment (=) Operators II

    Logical Operators -- Examples

    Increment & Decrement Operators I

    Increment & Decrement II

    Increment & Decrement III

    Left Shift bitwise operation

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan