Assignment Operators in C Language:
(1) Assignment Operators are used for assigning values to variables.
(2) Sample C language code and its output, as shown:
#include <stdio.h> #include <conio.h> // Assignment Operators in C Language int main() { int x; x = 5; printf(“Value of ‘=’: %d\n”, x); x = x + 10; printf(“Value of ‘+’: %d\n”, x); x = x – 9; printf(“Value of ‘-‘: %d\n”, x); x = x * 5; printf(“Value of ‘*’: %d\n”,x); x = x / 5; printf(“Value of ‘/’: %d\n”, x); x = x % 5; printf(“Value of ‘%’: %d\n”,x); x = x & 4; printf(“Value of ‘&’: %d\n”,x); x = x | 2; printf(“Value of ‘|: %d\n”,x); x = x ^ 4; printf(“Value of ‘^’: %d\n”,x); x = x >> 2; printf(“Value of ‘>>’: %d\n”,x); x = x << 4; printf(“Value of ‘<<‘: %d\n”,x); getch(); return 0; } |
(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.
(4) After building the code, press the “Run” button, as shown.
(5) After pressing the “run” button, the output screen is opened, as shown.
Assignment Operators | Description |
---|---|
= | Simple assignment |
*= | Multiplication assignment |
/= | Division assignment |
%= | Remainder assignment |
+= | Addition assignment |
-= | Subtraction assignment |
<<= | Left-shift assignment |
>>= | Right-shift assignment |
&= | Bitwise-AND assignment |
^= | Bitwise-exclusive-OR assignment |
|= | Bitwise-inclusive-OR assignment |