Simple assignment operator is used to assign a value to a variable. The assignment operation evaluates to the assigned value. Chaining the assignment operator is possible in order to assign a single value to multiple variables.
Assignment Operators
“=”: This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left.
for eg:-
a=5;
b=10
a will be assigned value of 5, and b will be assigned value of 10.
“+=”:This operator is combination of ‘+’ and ‘=’ operators. This operator first adds the current value of the variable on left to the value on right and then assigns the result to the variable on the left.
eg; ( a+=b ) can written as( a=a+b )
” -=” This operator is combination ‘-‘ and ‘=’ operator. This operator subtracts the value on right from the current value of the variable on left and then assigns the result to the variable on the left.
#include <stdio.h> // header files
#include <stdlib.h> // library files
int main()// main function
{
int a,b=10,c=5; // initialize the value
a=20;
b+=10;
c*=2;
printf("\n%d",b);
printf("\n%d",c);
return 0;
}
Output
20
10
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment