CH 2: Introduction To C++ Programming: 3.operation and Operator

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

CH 2: INTRODUCTION TO C++

PROGRAMMING
1. INTRODUCTION
2. FUNDAMENTAL OF C++

3.OPERATION AND OPERATOR


prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


WHAT IS THE OPERATORS??
Operator is an expression or evaluation of certain
value or condition to achieve final value.
WHY WE NEED OPERTOR?
Its needed for calculation and selection of the value
or condition.
prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


1. ASSIGMENT OPERATOR
Use the assignment operator = to assign the value of
a variable to an expression
In addition, assignment operator can also perform
simultaneously an arithmetic operator and assignment.
In expression of this type, the variable must be placed
on the left and assigned value on the right of the
assignment operator.
prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


1. ASSIGMENT OPERATOR

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


1. ASSIGMENT OPERATOR
EXAMPLE 2.3.1.1: please determine the final value of this operation.
a) Int i=2, j=5;
i *= j + 2;
b) Int = 3;
i += 3;

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


2. ARITHMETIC OPERATOR
WHAT IS AN ARITHMETIC OPERATOR?
Provide mathematical arithmetic calculation for numeric
quantities
Except for remainder (%), all other arithmetic operator can
accept mix of integer and real operands.
Generally, if one or both operands are reals then result will
be a real (or double to be exact)

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


2. ARITHMETIC OPERATOR

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


2. ARITHMETIC OPERATOR
EXAMPLE 2.3.2.1: Calculate or estimate the result for operation below?
a) Int a = 9, b = 2;
c = a / b;
b) Int a = -9, b = 2;
c = a / b;
c) Double a = 9, b = 2;
c = a/b
d) Double a = 4.75, b = 12.3456;
c = (a + b)/2;
e) Int a = 2, b = 7, c = 3;
d = a + b * c;
f) Int a = 2, b = 7, c = 3;
d = (a + b) * c;

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


3. INCREMENT AND DECREAMENT OPERATOR
Increment and decrement operators of ++ and modifies the
operand by adding 1 or subtract 1 to its value and cannot be used
with constant for this reason.
Let say, given i is variable, both i++ (postfix) and ++i (prefix) raise the
value of i by 1. both case, the operation i = i + 1 is perform.

prepared by omarabuhassan07@gmail.com

CH2.3: OPERATION AND OPERATOR


3. INCREMENT AND DECREAMENT OPERATOR

prepared by omarabuhassan07@gmail.com

10

CH2.3: OPERATION AND OPERATOR


3. INCREMENT AND DECREAMENT OPERATOR
EXAMPLE 2.3.3.1:
Calculate
a) Float x = 5.0;
b) Float x = 5.0;

y = x++ - 7.0 / 2;
y = ++x 7.0 / 2;

prepared by omarabuhassan07@gmail.com

11

CH2.3: OPERATION AND OPERATOR


4. CAST OPERATOR
Relation operator

prepared by omarabuhassan07@gmail.com

12

CH2.3: OPERATION AND OPERATOR


4. CAST OPERATOR
Logical operator

prepared by omarabuhassan07@gmail.com

13

CH2.3: OPERATION AND OPERATOR


PRIORITY IN OPERATORS

prepared by omarabuhassan07@gmail.com

14

You might also like