C Program to Demonstrate Compound Operators
Write C code to demonstrate the use of compound operators.
//Write a C program to demonstrate compound operator
#include<stdio.h>
int main()
{
int a = 7, c;
printf("The value of a is : %d\n",a);
c = a; // c is 5
printf("\nc = a \t --> \t");
printf("c = %d\n", c);
c += a; //c = a + c
printf("\nc += a\t --> \t");
printf("c = %d\n", c);
c -= a; // c = c - a
printf("\nc -= a\t --> \t");
printf("c = %d\n", c);
c *= a; // c = c * a
printf("\nc *= a\t --> \t");
printf("c = %d\n", c);
c /= a; // c = c / a
printf("\nc /= a\t --> \t");
printf("c = %d\n", c);
c %= a; // c = c % a
printf("\nc mode a --> \t");
printf("c = %d\n", c);
return 0;
}
Output:
The value of a is : 7
c = a --> c = 7
c += a --> c = 14
c -= a --> c = 7
c *= a --> c = 49
c /= a --> c = 7
c mode a --> c = 0