Operators and Expressions in C++

Operators and Expressions

Operator is a symbol that performs some operation. Simple operations may be addition,subtraction, multiplication, divison etc. So, operator is a symbol, which tellsthe compiler to do some operation or action.

For example,

2 + 3 = 5.Here the data 2 an 3 are known as operands. + is an operator, which performsummation of given numbers 2 and 3. The data 5 is the result of operation.

operands

C++ provides operators for combining arithmetic, relational, logical, bitwise, and conditional expressions. Note that every operator must return some value. For example, + operator returns sum of two numbers, * operator return multiplication of two numbers etc.

In above expression, the operator + operates on TWO operands. So, + is called binary operator. BI means 2. Rememeber bicycle has two wheels. Binacular has 2 eyes.

5 * 10 = 50. Here the data 5 an 10 are known as operands. * is an operator, which perform multiplication of given numbers 5 and 10. The data 50 is the result of operation.

z = x – y. Here the variables x an y are known as operands. – is an operator, whichperform subtracton of given numbers x and y. The result of operation is storedin the variable, z.

List ofsome basic operators is given in below table:

type of operators
Other classificationof operators
  • Unary operators
  • Binary operators
  • Ternary operators
Unary operators:

Some operators operate on singleoperand. They are called unary operators. Some examples are given below, whichwill be discussed later.

S. No. Symbol Meaning
1 ! Logical Not
2 ~ One’s complement
3 ++ Increment
4 Decrement
5 Unary minus
6 * Pointer operator
7 & Address of operator
8 sizeof Size of data type
9 (type) Type conversion

Note:

For example, the symbol * can be used for two purposes. It can be used as multiplication operator. And also used as pointer operator. This is known as operator overloading. The process of making an operator to exhibit different behaviours in different instances (times) is known as operator overloading. Real life example of overloading is the use of word: “square”. The word “square” has two meanings. When we say square of 5 = 25, the meaning is to find square of a number. Other meaning of a square is a geometric figure: SQUARE.

Binary operators:

Some operators operate on two operands. They are called binary operators. Someexamples are given below, which will be discussed later.

ternary operator
ternary operator program

Gopal Krishna

Hey Engineers, welcome to the award-winning blog,Engineers Tutor. I'm Gopal Krishna. a professional engineer & blogger from Andhra Pradesh, India. Notes and Video Materials for Engineering in Electronics, Communications and Computer Science subjects are added. "A blog to support Electronics, Electrical communication and computer students".

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »