What do you mean by Operators in C++ language? Discuss different types of operators used in C++.

An operator is a symbol which is going to operate on some operands. We have lots of operators in C++ language and they can be classified according to their specific task on operands on which they are going to operate. For example, a plus (+) is an operator which is further going to represent addition of two number. The basic operators (arithmetic) operators are addition (+), subtraction(-), multiplication (*), divide (/) and modules (%). In addition to these basic operators, many other operators are also there which allow you to manipulate numbers and text in some specific way. Assignment operator (=) is going to assign some value from right to left side. i.e int x=10. Here 10 is a value which is assigned to x, where x is a variable. According to the working of different operators we categorized operators into categories below:  


Type of Operators: 

1. Unary Operators: These are the operators which are going to operate on single value.
2. Binary Operators: These are the operators which are going to operate on two values.
3. Ternary Operators: These are the operators which are going to operate on two or more than two values.

Categories of Operators: 

According to the working on different operators, they are categorized into different types.

1. Arithmetic Operators: addition (+), subtraction(-), multiplication (*), divide (/) and modules (%).
Example: a+b,  a-b, a*b+c, a/c etc. 

2. Relational Operators: greater then (>), less then (<), greater then or equal to (>=), less then or equal to (<=), equal to (==), not equal to (!=).
Example: a>b, a>=b, a<=b, a==b, etc.

3. Logical Operators: and (&&), or (||) and not (!).
Example: a&&b, a||b etc.

4. Increments/Decrements Operators: pre/post increment (++), pre/post decrement (--)
Example: a++ (post), ++a (pre), a-- (post), --a(pre)


5. Conditional Operators: Symbol for this operator is (? :)
Example: a>b ? a:b , 19<10 ? 19:10. if a>b is true then a is executed and if false then b is executed.

6. Assignment Operators:  assignment (=), (+=), (-=), (*=), (/=) and (%=).
Example: a=10, a = a + 10 => a+=10, b  =  b * 10 => b*=10 etc

7. Special Operators: There are so many special operators in C++.
  a. sizeof(): find out the size or length.
  b. Ampersand (&): Address operator.i.e  int *p = &x, means you assign address of x to p.
  c. Arrow (->): used to access class member.
 d. Scope Resolution (::): Used to access global variable or defining class member function outside the class. 
 e. Dot (.) : Used to access class member using class object in main() function.

 f. Asterisk (*) : used to declare pointer like int *p; here p is known as pointer variable.
 g. delete: To delete and variables.
 h. new: Used to allocate dynamic memory to any variables.



Thanks
Mukesh Rajput


Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: