Page 36 - Modular_V2.0_C++_Flikpbook
P. 36
C++ provides the following assignment operators:
Operator Name Description Example
= Assignment It assigns the value of the right operand x = 5
to the left operand.
+= Addition assignment It adds right operand to the left operand x += 3
and assigns the result to left operand.
x+=3 is equivalent to x=x+3.
–= Subtraction assignment It subtracts right operand from the left x –= 3
operand and assigns the result to left
operand. x–=3 is equivalent to x=x–3.
*= Multiplication It multiplies right operand with the left x *= 3
assignment operand and assigns the result to left
operand. x*=3 is equivalent to x=x*3.
/= Division assignment It divides left operand with the right x /= 3
operand and assigns the result to left
operand. x/=3 is equivalent to x=x/3.
%= Remainder assignment It takes modulus of two operands and x %= 3
assigns the result to left operand. x%=3 is
equivalent to x=x%3.
Program 5: To use the assignment operators.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a = 5, b = 7, c = 2, d = 10;
a += 2;
cout<<"The value of a is: "<< a <<"\n";
b -= 1;
cout<<"The value of b is: "<< b <<"\n";
c *= a;
cout<<"The value of c is: "<< c <<"\n"; DOSBox 0.74, Cpu speed: max
The value of a is: 7
d %= 3;
The value of b is: 6
cout<<"The value of d is: "<< d <<"\n"; The value of c is: 14
The value of d is: 1
getch();
}
34
Touchpad MODULAR (Ver. 2.0)

