Assignment Operators in C

Assignment operators are used to assign the result of an expression to a variable.we have seen the usual assignment operator ‘=’.

Sr.No

Operators

Example

01

+=

a += 1

02

-=

a -= 1

03

*=

a *= n+1

04

/=

a /= n+1

05

%=

a %= b

Example


#include
int main() {
   int values;
   values = 10;
   values += 1;
   printf("\nValues is = %d", values);
   values = 10;
   values -= 1;
   printf("\nValues is = %d", values);
   values = 10;
   values *= 2;
   printf("\nValues is = %d", values);
   values = 11;
   values /= 4;
   printf("\nValues is = %d", values);
   values = 11;
   values %= 4;
   printf("\nValues is = %d", values);
   return 0;
}							
						
							

Output


Values is = 11
Values is = 9
Values is = 20 
Values is = 2
Values is = 3							
							
Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!