by Dinesh Thakur Category: Operator

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();
}

Arithmetic Assignment Operators in C++



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.