An assignment operator is used for assigning a value to a variable. The most common assignment operator is =(equal). The left side operand of the assignment operator is a variable and right side operand of the assignment operator is a value. The value on the right side must be of the same data-type of the variable on the left side otherwise the compiler will raise an error.
Compound Operator | Sample Expression | Expanded Form |
---|---|---|
+= | a+=5 | a=a+5 |
-= | a-=6 | a=a-6 |
*= | a*=7 | a=a*7 |
/= | a/=4 | a=a/4 |
%= | a%=9 | a=a%9 |
The code is a C program that demonstrates the use of compound assignment operators in C. Here is an explanation of each line of the code:
When you run this code, it will perform the compound assignment operation on variables and print the results in the console.
//Assignment operator #include<stdio.h> int main() { int a=10,b=5; //+= a+=b; //a=a+5 printf("A : %d",a); //15 a-=10; //a=a-10 printf("\nA : %d",a); return 0; }To download raw file Click Here
A : 15 A : 5
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions