Professional Documents
Culture Documents
Learning outcomes: At the end of the lecture, the students will have a
knowledge of different types of operators used in C programming,
operator’s precedence and associativity.
2
Operators in C Programming
• Operators are the symbols which operate on
values or variables. For example: + is an
operator to perform addition.
• C programming language has wide range of
operators to perform various operations. For
better understanding of operators, these
operators can be classified as:
Arithmetic Operators
Increment and Decrement Operators
Assignment Operators
Relational Operators
Logical Operators
Conditional Operators
Bitwise Operators
Special Operators
Arithmetic Operators
Operator Meaning of operator
+ addition or unary plus
- subtraction or unary minus
* multiplication
/ division
% remainder after division
(modulo division)
• Multiplicative: *, /, %
• Additive: +, -
• Relational: <, >, <=, >=
• Equality: ==, !=
• Logical AND: &&
• Logical OR: ||
• Assignment: =, +=, -=, *=, /=, %=
• In C, precedence of arithmetic operators
(*,%,/,+,-) is higher than relational
operators(==,!=,>,<,>=,<=) and precedence of
relational operator is higher than logical
operators(&&, || and !). Suppose an
expression:
(a>b+c&&d)
This expression is equivalent to:
((a>(b+c))&&d)
i.e, (b+c) executes first
then, (a>(b+c)) executes
then, (a>(b+c))&&d) executes
• Operator precedence is why the expression 5 + 3 *
2 is calculated as 5 + (3 * 2), giving 11, and not as (5 +
3) * 2, giving 16.
• We say that the multiplication operator (*) has
higher "precedence" or "priority" than the addition
operator (+), so the multiplication must be
performed first.
1. 10 ÷ 2 + 12 ÷ 2 × 3 =
2. 7+3×5=
3. 7+3×4÷2−5×6=
4. (7 +3 ) x 4 / 2 - 5 x 6=
5. 3+4×5=
6. 4 × 32 =
7. [4 − 1 + (5 + 3)] =
8. 15 − 12 × 2/(12/3) + 22=
9. (2 + 6)/4 × 3 =
Answers
1. 23
2. 22
3. -17
4. -10
5. 23
6. 36
7. 11
8. 13
9. 6