An operator is a symbol that performs an operation. The data on which operations are carried out are called operands.
Following are the operators
1) lnput(>>) and output(<<) operators: are used to perform input and output operation.
Eg. cin>>n;
cout<<n
2) Arithmetic operators: It is a binary operator. It is used to perform addition(+), subtraction(-), division (/), multiplication (*) and modulus (%- gives the remainder) operations.
Eg. If x=10 and y=3 then
x+y |
x-y |
x*y |
x/y |
x%y |
13 |
7 |
30 |
3 |
1 |
x/y = 3, because both operands are integer, “to get the floating point result one of the operand must be float.
3) Relational operator: It is also a binary opera- tor. It is used to perform comparison or relational operation between two values and it gives either true(1) px false(O). The operators are ,>=,== (equallty)and != (not equal to)
Eg. If x-10 and y=3 then
x<y |
x<=y |
x>y |
x>=y |
x==y |
x!=y |
False |
False |
True |
True |
False |
True |
4) Logical operators : Here AND(&&), OR(||) are binary operators and NOT(!) is a unary operator. It is used to combine relational operation? and it gives either true(1) or false(O).
If x=True and y=False then
x && x |
x && y |
y && x |
y && y |
True |
False |
False |
False |
Both operands must be true to get a true value in the case of AND(&&) operation
If x=True and y=False then
x || x |
x || y |
y || x |
y || y |
True |
False |
False |
False |
Either one of the operands must be true to get a true value in the case of OR(||) operation If x=True and y=False then
5) Conditional operator: It is a ternary operator hence it needs three operands. The operator is?:. Syntax: expression ? value if true : value if false. First evaluates the expression if it is true the second part wilt be executed otherwise the third part will be executed.
Eg. If x=10 and y=3 then x>y ? cout< Here the output is 10.
6) sizeof( ): This operator is used to find the size used by each data type. Eg. sizeof(int) gives 2.
7) Increment and decrement
a) Increment operator (++): It is used to increment the value of a variable by one i.e., x++ is equivalent to x=x+1;
b) Decrement operator (–) : It is used to decrement the value of a variable by one i.e., x-is equivalent to x = x-1.
8) Assignment operator (=) : lt is used to assign the value of a right side to the left side variable.eg. x=5; Here the value 5 is assigned, to the variable x.