C++ provides a short form when a variable is incremented, decremented etc. For example
j = j + 3; and j = j -3;
can also be written as
j += 3; and j -= 3;
and
j =j * 3;
can also be written as
j*=3;
+=, -=, *= are arithmetic assignment operators. The other arithmetic assignment operators are /=, %= .
Write C++ program illustrates the use of arithmetic assignment operators.
#include <iostream.h> #include<conio.h> void main() { int count=10; clrscr(); cout<<"Initial value of Count is: "; cout<<count<<"\n" ; count+=1; cout<<" count "<<count<<"\n"; count-=2; cout<<"count "<<count<<"\n"; count*=3; cout<<" count "<<count<<"\n"; count/=2; cout<<"count "<<count<<"\n"; getch(); }