Operators

Default Image

symbol that tells compiler to perform
some arithmetic task is called an operator. C++ have many types of
operators. We can categorize operators in two types as follows:

  1.  Binary operators
  2. Unary operators

        Binary operators:


The operator that required two data items
to perform task is called binary operator. Such as arithmetic, logical,
and relational operators are example of binary operator. Arithmetic
operators perform arithmetic on tow values or variables. Such as
addition (+), subtraction (-), multiplication (*), division (/) and
modulus (%). Relational operation defines a relation between tow
quantities or variables such as less than (<), greater than (>),
less than or equal (<=) and greater than or equal (>=). Logical
operators that return us in the form of true or false, such as logical
and (&&), logical or (||) are example of logical expression.


        Unary operators


An operator that only need one data item
to show result called unary operators. We have a few unary operators
such as logical not (!), increment operator (++) and decrement operator
(–).


        Operators precedence:


Operator precedence fixes the group of
terms in an equation. This moves how an equation is evaluated. Few
operators have higher precedence than others; for example, the
multiplication operator has higher precedence than the addition
operator. For example, a = 6 + 4 * 3; here, a is assigned 18, not 30
because operator * has higher precedence than +, so it first gets
multiplied with 3*4 and then adds into 6. Here, operators with the
highest precedence look at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators
will be evaluated first.



































































Category Operator Associativity
Postfix () [] -> . ++ – – Left to right
Unary + – ! ~ ++ – – (type)* & sizeof Right to left
Multiplicative * / % Left to right
Additive + – Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left
Comma , Left to right

Read Count: 3 times

Comments

No comments yet.

Leave a Comment