Assignment Operators

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
i=i+1; i+=1;
t=t*m-k; t*=m-k;
m=m/1; m/=1;
h=h%p; h%=p;

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.

yashan has written 70 articles

One thought on “Assignment Operators

  1. kayanja says:

    see i hve tried running the program in linux bt it seems that it is giving me some one error which talks of the the invalid operands in this program wat shd i do please send me an email for the solution in such cases

Cancel reply

Leave a Reply to kayanja

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>