C++ examples for Function:Global Variable
Demonstrate global variables
#include <iostream> using namespace std; #include <conio.h> //for getch() char ch = 'a'; //global variable ch void getachar();/* www . j a va 2 s . c om*/ void putachar(); int main() { while( ch != '\r' ) //main() accesses ch { getachar(); putachar(); } cout << endl; return 0; } void getachar() //getachar() accesses ch { ch = getch(); } void putachar() //putachar() accesses ch { cout << ch; }