Using the increment and decrement operators - C++ Operator

C++ examples for Operator:Increment and decrement operators

Description

Using the increment and decrement operators

Demo Code

#include <iostream> 
 #include <stdlib.h> 

 using namespace std; 

 int main(int argc, char *argv []) 
 { /*from   w  w w  .j a va 2 s.  co  m*/
   // Declare an integer variable. 
   int anInt; 

   // Prompt the user for an integer. 
   cout << "Please input an integer and press Enter: "; 
   cin >> anInt; 

   // Increment the integer and show the result . 
   anInt++; 
   cout << "After increment : " << anInt << endl; 

   // Decrement the integer and show the result . 
   anInt--; 
   cout << "After decrement 1: " << anInt << endl; 

   // Decrement the integer and show the result . 
   anInt--; 
   cout << "After decrement 2: " << anInt << endl; 

   return 0; 
}

Result


Related Tutorials