C++ examples for Function:Function Creation
Using two local variables with the same name as counting variables.
#include <iostream> using namespace std; int do_fun(); // Prototype int main()/*from w w w.j a v a2 s. c o m*/ { int ctr; // Loop counter. for (ctr=0; ctr<=10; ctr++) { cout << "main()'s ctr is " << ctr << "\n"; } do_fun(); // Call second function. return 0; } int do_fun() { int ctr; for (ctr=10; ctr>=0; ctr--) { cout << "do_fun()'s ctr is " << ctr << "\n"; } return 0; // Return to main(). }