0% found this document useful (0 votes)
29 views

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

This document discusses operators in C++ programming. It explains that operators are used for calculations and evaluating values or conditions. There are several types of operators discussed, including assignment, arithmetic, increment/decrement, relation, logical, and cast operators. Examples are provided to demonstrate how to use different operators to perform calculations and evaluate expressions in C++ code. The document also notes that operator precedence determines the order in which operations are performed in an expression with multiple operators.

Uploaded by

lexiaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

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

This document discusses operators in C++ programming. It explains that operators are used for calculations and evaluating values or conditions. There are several types of operators discussed, including assignment, arithmetic, increment/decrement, relation, logical, and cast operators. Examples are provided to demonstrate how to use different operators to perform calculations and evaluate expressions in C++ code. The document also notes that operator precedence determines the order in which operations are performed in an expression with multiple operators.

Uploaded by

lexiaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

CH 2: INTRODUCTION TO C++

PROGRAMMING
1. INTRODUCTION
2. FUNDAMENTAL OF C++

3.OPERATION AND OPERATOR


prepared by [email protected]

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 [email protected]

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 [email protected]

CH2.3: OPERATION AND OPERATOR


1. ASSIGMENT OPERATOR

prepared by [email protected]

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 [email protected]

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 [email protected]

CH2.3: OPERATION AND OPERATOR


2. ARITHMETIC OPERATOR

prepared by [email protected]

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 [email protected]

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 [email protected]

CH2.3: OPERATION AND OPERATOR


3. INCREMENT AND DECREAMENT OPERATOR

prepared by [email protected]

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 [email protected]

11

CH2.3: OPERATION AND OPERATOR


4. CAST OPERATOR
Relation operator

prepared by [email protected]

12

CH2.3: OPERATION AND OPERATOR


4. CAST OPERATOR
Logical operator

prepared by [email protected]

13

CH2.3: OPERATION AND OPERATOR


PRIORITY IN OPERATORS

prepared by [email protected]

14

You might also like