Unit 4 - The Operators
C++ is very rich in built-in operators. Operators trigger some computations when applied to operands in an expression. There are several general classes of operators. But for now, we will present just the arithmetic, relational, logical and assignment operators.
a-Arithmetic Operators
There are seven arithmetic operators in C++:-
Examples of operation involving integer variables. With a=7 and b=2, the expression on the values on the right.
Note: You can assign a positive or negative number to a variable by using a unary +
or - . Example:
a = -20 // assigns ‘a’ a negative 20
b = +20 // assigns ‘b’ a positive 20 ( + sign normally not needed)
Unary operators operate on single value. Thus the size of operator is a unary operator. So are the decrement and increment operator.
b-Relational Operators
There are six relational operators and three logical operators in C++:-
The result of evaluation of a relational operation is either true(represented by 1) or false (represented by 0). For example, if a = 7 and b = 5, then a
c-Logical Operators
There are three logical operators in C++:
*Hierarchy of Operators
The hierarchy of operator precedence form highest to lowest is summarized below:
a-Arithmetic Operators
There are seven arithmetic operators in C++:-
Examples of operation involving integer variables. With a=7 and b=2, the expression on the values on the right.
Note: You can assign a positive or negative number to a variable by using a unary +
or - . Example:
a = -20 // assigns ‘a’ a negative 20
b = +20 // assigns ‘b’ a positive 20 ( + sign normally not needed)
Unary operators operate on single value. Thus the size of operator is a unary operator. So are the decrement and increment operator.
b-Relational Operators
There are six relational operators and three logical operators in C++:-
The result of evaluation of a relational operation is either true(represented by 1) or false (represented by 0). For example, if a = 7 and b = 5, then a
c-Logical Operators
There are three logical operators in C++:
*Hierarchy of Operators
The hierarchy of operator precedence form highest to lowest is summarized below:
No comments:
Post a Comment