Operators:
An operator is a symbol which will be manipulated on
the operand.
They are classified in three types:
·
Unary operators
·
Binary operators
·
Ternary operators
1.
Unary operators:- unary operators are the operators which will be
manipulated on single operand.Eg: - -a (unary minus)
2. Binary operators:- binary operators are the operators which will be manipulated on minimum two operands.
Eg: - a+b;
Hierarchy and associativity i.e. direction they have to solve.
Category | Operators | Associativity |
Highest category | () function call, [] subscript, -> pointer to member access, . Member access | L to R |
Unary category | ~ is compliment, ! not, - unary minus, + unary plus, ++ -- preincrement/predecrement, & address of, * value of address, sizeof, typecast | R to L |
Arithmetic category | *,/,%
modular division/modulus + addition,- subtract |
L to R |
Bitwise category | <<
left shift >> Right shift |
L to R |
Relational category | < less than, <= less than or equal to, > greater than, >= greater than or equal to | L to R |
Equality | == comparison, != not equal to | L to R |
Bitwise category | & bitwise AND | L to R |
^ bitwise exclusion OR | ||
| bitwise OR | ||
Logical category | && logical AND | L to R |
|| logical OR | ||
Ternary operator | ? : | R to L |
Assignment operator | = simple assignment, *= multiply and assign, /=, %=,+=,-=,<<=,>>=,&=,^=,|= | R to L |
Comma operator | , comma | L to R |
Unary category | ++, -- post increment/post decrement | R to L |
Arithmetic operator:
Arithmetic expression is taking place by valid combination of numeric variable, numeric constant and arithmetic operator.
Eg: a+b;
1)47%5à2, (2) -47%5à -2 (3)47%-5à2 (4)-47%-5à-2
Relational/comparison operator:
·
A relational expression is taking place by valid
combination of numeric variable, numeric constant and relational operator.
·
A relational operator always returns either 1 or 0.
Eg:
a>b1)47>4à1 (2)67>65à0 (3)if a=7,b=8 then a<bà1
Logical operator:
·
A logical expression is a valid combination of
logical values, variables and operators.
·
A logical value can be combined with relational
expression.
·
A logical operator also returns either 1 or 0.
Eg: 1) a=5>4&& 4>3à1 (2) a=7&&8à1 (3) a=7||0à1
(4) a=1+(2&&2)+3à5 (5) a=!-67à0 (6)a=!(-3>3)à1
No comments:
Post a Comment