Compound Assignment Statement In C++
The assignment statement can also be used to assign one value to many variables. This type of assignment statement is called Compound Assignment Statement.
to assign an integer value 16 to two integer type variables x and y, the compound assignment statement is written as:
x = y = 16;
Program:
Write a program to assign a value 515 to integer type variables x,y,a,b, and c. Also calculate the sum of the variables and print the result on the screen.
#include <iostream.h>
main ( )
{
int x, y, a, b, c, s;
x=y=a=b=c=515;
s=x+y+a+b+c;
cout<<"sum = " << s;
}
Assignment Operator (=)
The assignment operator assigns a value to a variable.
x=5;