In C programming language Assignment operators are used for assigning an expression or value (constant) to a variable. Assignment Operators are further sub divided into two types. These are –
- Simple Assignment Operator
- Short Hand Assignment Operator OR Arithmetic Assignment Operator.
Simple Assignment Operator
Simple assignment operator is ‘ = ‘ (equal to). The general syntax of simple assignment operator is as:
v = constant value or variable or expression;
Where v is variable and expression be any arithmetic expression. For ex, some of the valid simple assignment expressions are as:
sum=0; i=1; a=b; /* Here b is another variable assigning to a */ si=(p*r*t/100);
Short Hand or Arithmetic Assignment Operator
Short Hand Operators have equal to ( = ) sign with all the arithmetic operators. The general syntax of short hand or arithmetic assignment operators are as:
v arithmetic operator = constant value or expression;
Where v is the varialbe and expression be an arithmetic expression. Here the arithmetic operators used are *, /, +, -, %.
For example, some valid expressions having simple assignment and hand assignment are as shown in table:
|Simple Assignment||Short Assignment|
It is not necessary to use shorthand assignment operator. If you feel difficulty in using them then only use the simple assignments. Also in C programming language always a Right hand value, variable, constant or expression is assigned to the Left hand variable or expression. For example if you want to assign the value of b to a then a=b; will be written not b=a as R-value is assigned to the L-value.