Assignment Operators

The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.

Example

x = a + b
Here the value of a + b is evaluated and substituted to the variable x.

In addition, C has a set of shorthand assignment operators of the form. var oper = exp;

Here var is a variable, exp is an expression and oper is a C binary arithmetic operator. The operator oper = is known as shorthand assignment operator

Example

x + = 1 is same as x = x + 1
The commonly used shorthand assignment operators are as follows

Shorthand assignment operators

Statement with simple
assignment operator

Statement with
shorthand operator

a = a + 1 a += 1
a = a – 1 a -= 1
a = a * (n+1) a *= (n+1)
a = a / (n+1) a /= (n+1)
a = a % b a %= b
Back