Assignment operators in C

Assignment operators-: Assignment operators are used to assign the result of an expression to a variable. We have seen the usual assignment operators “= “. C has a set of shorthand assignment operators of the form as like

               s op= exp ;

where s is a variable, exp is an expression and op is a c binary arithmetic operators op=OP.

Assignment operators are used to assigning value to a variable. The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error.

The list of assignment operator -: There are some assignment operator in c programming langue. These are  (=), (+=),(-=),(*=),  (/=) and(= %) .

1-:   “=” -: This is the simplest operator. It assign the value of the left side variable . For example we take a variable name  a then we use the a=10; the left side variable a value assign the 10.

2-: “= +” -:   This assignment operator is the combination of two. first is the = and second is the +. for example we take a variable name (a) and its value assign a=a+1; 

3-: “= -“-:  This assignment operator is the combination of two. first is the = and second is the -. for example we take a variable name (a) and its value assign a=a-1; 

4-: “= * +”-:  This assignment operator is the combination of two. first is the = and second is the * for example we take a variable name (a) and its value assign a=a*(n+1);

5-: “= * -“-:  This assignment operator is the combination of two. first is the = and second is the -. for example we take a variable name (a) and its value assign a=a*(n-1);

6-: “= -“-:  This assignment operator is the combination of two. first is the = and second is the -. for example we take a variable name (a) and its value assign a=a%1\n;

assignment operators list -:

  1. a=a+1
  2. a=a-1
  3. a=a*(n+1)
  4.  a=a/(n+1)
  5. a=a%n

The assignment has some advantage here

  1. What appears on the left hand side need not be repeated and therefore it becomes easier to writing.
  2. The statement is easy to read
  3. statement is more efficient

Example -:  We write a program here

#define  N  100
#define  A  2

Void main()
  
   {
     int x;

      x= A;

   While (x < N)

    {

   printf("%d\n",x);

    x*=x;
 
    }
getch();

}

Output of this program

2
4
16

More about the c programming language operator

Leave a Comment