An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C++ is rich in built-in operators and there are almost 45 different operators.Operator operates on constants and variables which are called operands. Operators may also be classified on the number of operands they act on either
Unary Operators
Unary operators have only one operand; they are evaluated before any other operation containing them gets evaluated.
Increment Operator
Increment operator is used to increasing the value of an integer by one. This is represented by “++”.
Example: a++, a+1
Decrement Operator
Decrement operator is used to decreasing the value of an integer by one. This is represented by “--”.
Example: a--, a-1
Prefix increment/decrement
When an increment or decrement operator precedes its operand, it is called prefix increment or decrement (or pre-increment / decrement). In prefix increment/decrement, C++ performs the increment or decrement operation before using the value of the operand.
Example: If sum = 10 and count =20 then
Sum = sum + (++count);
First count incremented and then evaluate sum = 31. Postfix increment/decrement: When an increment or decrement operator follows its operand, it is called postfix increment or decrement (or post-increment / decrement). In postfix increment/decrement, C++ first uses the value of the operand in evaluating the expression incrementing or decrementing the operand’s value.
Example: If sum = 10 and count =20 then
Sum = sum + (count++);
First evaluate sum = 30, and then increment count to 21.
Binary Operators
The binary operators are those operators that operate on two operands. They are as arithmetic, relational, logical, bitwise, and assignment operators.
Arithmetic Operator
Arithmetic operators are used to performing the basic arithmetic operations such as arithmetic, subtraction, multiplication, division and modulo division (remainder after division).
Relational Operator
Relational Operator is used to comparing two operands given in expressions. They define the relationship that exists between two constants. For example, we may compare the age of two persons or the price of two items….these comparison can be done with the help of relational operators.
Logical Operators
Logical operators are used to testing more than one condition and make decisions.
Bitwise Operators
A bitwise operator works on bits and performs bit by bit operation. Bitwise operators are used in bit level programming.
Unary Operators
Unary operators have only one operand; they are evaluated before any other operation containing them gets evaluated.
Increment Operator
Increment operator is used to increasing the value of an integer by one. This is represented by “++”.
Example: a++, a+1
Decrement Operator
Decrement operator is used to decreasing the value of an integer by one. This is represented by “--”.
Example: a--, a-1
Prefix increment/decrement
When an increment or decrement operator precedes its operand, it is called prefix increment or decrement (or pre-increment / decrement). In prefix increment/decrement, C++ performs the increment or decrement operation before using the value of the operand.
Example: If sum = 10 and count =20 then
Sum = sum + (++count);
First count incremented and then evaluate sum = 31. Postfix increment/decrement: When an increment or decrement operator follows its operand, it is called postfix increment or decrement (or post-increment / decrement). In postfix increment/decrement, C++ first uses the value of the operand in evaluating the expression incrementing or decrementing the operand’s value.
Example: If sum = 10 and count =20 then
Sum = sum + (count++);
First evaluate sum = 30, and then increment count to 21.
Binary Operators
The binary operators are those operators that operate on two operands. They are as arithmetic, relational, logical, bitwise, and assignment operators.
Arithmetic Operator
Arithmetic operators are used to performing the basic arithmetic operations such as arithmetic, subtraction, multiplication, division and modulo division (remainder after division).
Relational Operator
Relational Operator is used to comparing two operands given in expressions. They define the relationship that exists between two constants. For example, we may compare the age of two persons or the price of two items….these comparison can be done with the help of relational operators.
Logical Operators
Logical operators are used to testing more than one condition and make decisions.
Bitwise Operators
A bitwise operator works on bits and performs bit by bit operation. Bitwise operators are used in bit level programming.
C++ Operators
Reviewed by Unknown
on
04:28
Rating:
No comments: