Operators In C
Operators In C
- Arithmetic Operators (+,-,*,/,%)
- Assignment Operators (=,+=,*=,-=,/=)
- Relational Operators (>,<,>=,<=,==,!=)
- Conditional Operators
- Increment/ Decrement Operators (++,--)
- Special Operators (comma, sizeof, * etc)
- Bitwise Operators
- Logical Operators
Points on detail:
General Syntax of Conditional Operators
variable = exp 1 ? exp 2 : exp 3;
E.g l = a>b ? a:b;
Here, if a>b then assign l = a else l = b
General Syntax of Logical Operators
General Syntax of Logical Operators
if (exp 1 && exp 2) if (exp 1 || exp 2) if (!a)
{.........................} {.........................} {.........................}
else {...............} else {...............} else {...............}
Precedence and Associativity
The data type and the value of an expression depends on the data types of the operands and the order of evaluation of operators which is determined by the precedence and associativity of operators. Let us first consider the order of evaluation. When expressions contain more than one operator, the order in which the operators are evaluated depends on their precedence levels. A higher precedence operator is evaluated before a lower precedence operator. If the precedence levels of operators are the same, then the order of evaluation depends on their associativity (or, grouping). In Chapter we briefly discussed the precedence and associativity of arithmetic operators. Table shows the precedence levels and associativity of all C operators.
Basic:
+, -, *, /, %
Low---------- (+, -)
High----------(*, /, %)
In a + b - c * d / e ------------the precedence is as Left to Right.
{.........................} {.........................} {.........................}
else {...............} else {...............} else {...............}
Precedence and Associativity
The data type and the value of an expression depends on the data types of the operands and the order of evaluation of operators which is determined by the precedence and associativity of operators. Let us first consider the order of evaluation. When expressions contain more than one operator, the order in which the operators are evaluated depends on their precedence levels. A higher precedence operator is evaluated before a lower precedence operator. If the precedence levels of operators are the same, then the order of evaluation depends on their associativity (or, grouping). In Chapter we briefly discussed the precedence and associativity of arithmetic operators. Table shows the precedence levels and associativity of all C operators.
Basic:
+, -, *, /, %
Low---------- (+, -)
High----------(*, /, %)
In a + b - c * d / e ------------the precedence is as Left to Right.
Post a Comment