Write a Program in C++ That Do Preincrementing and Postincrementing

// Preincrementing and postincrementing.
#include <iostream>
using namespace std;

int main()
{
   // demonstrate postincrement
   c = 5; // assign 5 to c
   cout << c << endl; // print 5
   cout << c++ << endl; // print 5 then postincrement
   cout << c << endl; // print 6                     

   cout << endl; // skip a line

   // demonstrate preincrement
   c = 5; // assign 5 to c  
   cout << c << endl; // print 5                    
   cout << ++c << endl; // preincrement then print 6
   cout << c << endl; // print 6
} // end main

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...