Saturday 25 July 2015

Arithmetic assignment and decrement

Leave a Comment
Questions:

Write a program that generates the following output:
10
20
19
Use an integer constant for the 10, an arithmetic assignment operator to generate the 20,and a decrement operator to generate the 19.

Code:

// exercises arithmetic assignment and decrement
#include <iostream>
using namespace std;
int main()
{
       int var = 10;
       cout << var << endl; // var is 10
       var *= 2; // var becomes 20
       cout << var-- << endl; // displays var, then decrements it
       cout << var << endl; // var is 19
       return 0;
}



Output:


If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: