Mega Code Archive

 
Categories / C++ Tutorial / Language Basics
 

Using a static long variable

#include <iostream> #include <iomanip> using std::cout; using std::endl; long next(); int main() {   for(int i = 0 ; i < 30 ; i++) {     cout << std::setw(12) << next ();   }   cout << endl;   return 0; } long next () {   static long last = 0;   last = last + 1;      return last; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30