Types of Assignment Operators in C
An assignment operator is basically a binary operator that helps in modifying the variable to its left with the use of the value to its right. We utilize the assignment operators to transform and assign values to any variables.
Here is a list of the assignment operators that you can find in the C language:
basic assignment ( = )
subtraction assignment ( -= )
addition assignment ( += )
division assignment ( /= )
multiplication assignment ( *= )
modulo assignment ( %= )
bitwise XOR assignment ( ^= )
bitwise OR assignment ( |= )
bitwise AND assignment ( &= )
bitwise right shift assignment ( >>= )
bitwise left shift assignment ( <<= )
SIMPLE C PROGRAMMING USING ASSIGNMENT OPERATORS
// C program to illustrate the arithmatic operators
#include <stdio.h>
int main()
{
int a = 25, b = 5;
// using operators and printing results
printf("a = b : %d\n", a = b);
printf("a += b : %d\n", a += b);
printf("a -= b : %d\n", a -= b);
printf("a *= b : %d\n", a *= b);
printf("a /= b : %d\n", a /= b);
printf("a %= b : %d\n", a %= b);
printf("a &= b : %d\n", a &= b);
printf("a |= b : %d\n", a |= b);
printf("a >>= b : %d\n", a >> b);
printf("a <<= b : %d\n", a << b);
return 0;
}
Output
a = b : 5
a += b : 10
a -= b : 5
a *= b : 25
a /= b : 5
a %= b : 0
a &= b : 0
a |= b : 5
a >>= b : 0
a <<= b : 160
