Computer Science, asked by bharathkumbham8254, 1 year ago

Q9What are operators? Briefly write about the types of operators used in C++

Answers

Answered by pratyushssb
0
Operators are special type of functions, that takes one or more arguments and produces a new value. For example : addition (+), substraction (-), multiplication (*) etc, are all operators. Operators are used to perform various operations on variables and constants.

Assignment Operators

Operates '=' is used for assignment, it takes the right-hand side (called rvalue) and copy it into the left-hand side (called lvalue). Assignment opberator is the only operator which can be overloaded but cannot be inherited.

Mathematical Operators

There are operators used to perform basic mathematical operations. Addition (+) , subtraction (-) , diversion (/) multiplication (*) and modulus (%) are the basic mathematical operators. Modulus operator cannot be used with floating-point numbers.

Relational Operators

These operators establish a relationship between operands. The relational operators are : less than (<) , grater thatn (>) , less than or equal to (<=), greater than equal to (>=), equivalent (==) and not equivalent (!=).

Logical Operators

The logical operators are AND (&&) and OR (||). They are used to combine two different expressions together.

If two statement are connected using AND operator, the validity of both statements will be considered, but if they are connected using OR operator, then either one of them must be valid. These operators are mostly used in loops (especially while loop) and in Decision making.

Bitwise Operators

There are used to change individual bits into a number. They work with only integral data types like char, intand long and not with floating point values.

Bitwise AND operators &

Bitwise OR operator |

And bitwise XOR operator ^

And, bitwise NOT operator ~

They can be used as shorthand notation too, & = , |= ,^= , ~= etc.

Shift Operators

Shift Operators are used to shift Bits of any variable. It is of three types,

Left Shift Operator <<

Right Shift Operator >>

Unsigned Right Shift Operator >>>

Unary Operators

These are the operators which work on only one operand. There are many unary operators, but increment ++ and decrement -- operators are most used.

Other Unary Operators : address of &, dereference *,new and delete, bitwise not ~, logical not !, unary minus - and unary plus +.

Ternary Operators

The ternary if-else ? : is an operator which has three operands.

Comma Operators

This is used to separate variable names and to separate expressions. In case of expressions, the value of last expression is produced and used.







Similar questions