Wednesday, August 26, 2020

9.1.7 Assignment Operators

  • Assignment operators are used to assign values of variables to each other. 
  • Below are some of the different assignment operators used in C language.

Operators

 

Description

 

=

This operator assigns the value of the operand of the right side to the

operand of the left side.

 

 

+=

This operator assigns the value of the operand of right side in the

operand left side and assigns the operand with the result left side. You can also write it in this way. a = a + b;

 

 

 

+=

This operator subtract the value of the operand of the right side operand from the value of operand left side and store it in the result left side variable.

You can also write it in this way. a = a-b;

 

 

*=

This operator stores the left side of the operand with the value of the

operand value of the right side and stores the result in the operand of

the left side.

 

 

/=

It divides the value of operator left operand with the value of right operand and stores the result in the operand of the left side.

 

 

%=

This operator divides the value of the operand left side with the value of the operand of the right side and stores the remaining result in the operand of the left side.



EXAMPLE :-


// Assignment operators in C.
#include <stdio.h>
int main()
{
int x = 20, y;

y = x;
printf("y is = %d\n", y);
y += x;
printf("y is = %d\n", y);
y -= x;
printf("y is = %d\n", y);
y *= x;
printf("y is = %d\n", y);
y /= x;
printf("y is = %d\n", y);
y %= x;
printf("y is = %d\n", y);

return 0;
}


OUTPUT


y is = 20 y is = 40 y is = 20 y is = 400 y is = 20 y is = 0





No comments:

Post a Comment

Please do not any spam link in Comment Box