2.6Expressions, Assignment and Arithmetic Operators
Covers IGNOU MCS-201 §2.11, 2.12, 2.13
Expressions are how a program calculates. This section introduces the vocabulary (expression, operator, operand), the assignment operator, and the five arithmetic operators, with the exact rules C uses for integer division, remainders, mixed types and order of evaluation.
Expressions, operators and operands
An operator is a symbol that performs an operation; an operand is a value it operates on. In a + 5, + is the operator and a and 5 are operands. Operators are classified by how many operands they take:
Kind
Operands
Examples
Unary
1
-x, !flag, ++i
Binary
2
a + b, x > y
Ternary
3
c ? a : b
The assignment operator
variable = expression; evaluates the right-hand side and stores the result in the variable on the left. The left side must be something that can hold a value (a variable), not a constant or an expression: 5 = a; and a + b = c; are errors.
An assignment is itself an expression whose value is the value stored, so a = b = 0; sets both to 0 (assignment groups from right to left).
When the types differ, the value is converted to the type of the variable on the left: int i = 4.6; stores 4 (the fraction is dropped), and float b = 20; stores 20.0.
Arithmetic operators
Operator
Meaning
Example
Result
+
Addition
7 + 2
9
-
Subtraction
7 - 2
5
*
Multiplication
7 * 2
14
/
Division
7 / 2
3 (integers)
%
Remainder (modulus)
7 % 2
1
So 10 / 3 is 3, 10 % 3 is 1, 15 % 4 is 3, -7 / 2 is −3, and -7 % 2 is −1 (the remainder takes the sign of the dividend). Dividing by zero is undefined behaviour. C has no exponent operator: a**b is an error, and powers are written with repeated multiplication or the pow function from <math.h>.
Mixed types
When an operator has one integer and one floating operand, the integer is converted and real arithmetic is used:
Expression
Result
5 / 3
1
5.0 / 3
1.666667
5 / 3.0
1.666667
5.0 / 3.0
1.666667
The type of each operation depends only on its own operands. The variable on the left of = does not change how the right-hand side is calculated; the finished result is converted only when it is stored.
Precedence and associativity of arithmetic operators
Precedence decides which operator is applied first; associativity decides the order for operators of equal precedence.
Parentheses first; the innermost pair first.
*, / and %: these three have equal precedence, so evaluate them left to right in the order they appear.
+ and -: these two have equal precedence, so evaluate them left to right in the order they appear. Neither one comes “before” the other; in 10 - 4 + 2 the - is done first only because it is further left, giving 8.
Algebraic expressions must be written in a single line with explicit *:
Algebra
C
m+na⋅4c2−d
(a * 4 * c * c - d) / (m + n)
ab−c(e+f)⋅4
a * b - (e + f) * 4 / c
b+ca
a / (b + c)
Key takeaways
An expression combines operands and operators; operators are unary, binary or ternary.
= stores the right-hand value in the left-hand variable, converting it if needed.
Integer / truncates towards zero; % gives the remainder and works only on integers.
*, /, % come before +, -; equal precedence goes left to right; parentheses override.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Evaluate 3 + 4 * 5 % 3 - 6 / 4 step by step, with integer operands.
Show worked answer
First the operators *, % and /, from left to right: 4 * 5 = 20; then 20 % 3 = 2; then 6 / 4 = 1 (integer division). The expression becomes 3 + 2 - 1. Then + and - from left to right: 3 + 2 = 5, and 5 − 1 = 4. The value is 4.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-types-operators-and-expressions/expressions-assignment-and-arithmetic-operators/ to read this page.