Demonstrates arithmetic assignment operators - C++ Operator

C++ examples for Operator:Arithmetic Operator

Description

Demonstrates arithmetic assignment operators

Demo Code

#include <iostream>
using namespace std;
int main()/*from   w w  w  .ja va2  s  . com*/
{
   int ans = 27;
   ans += 10;              //same as: ans = ans + 10;
   cout << ans << ", ";
   ans -= 7;               //same as: ans = ans - 7;
   cout << ans << ", ";
   ans *= 2;               //same as: ans = ans * 2;
   cout << ans << ", ";
   ans /= 3;               //same as: ans = ans / 3;
   cout << ans << ", ";
   ans %= 3;               //same as: ans = ans % 3;
   cout << ans << endl;
   return 0;
}

Result


Related Tutorials