C++ global variables
#include <iostream> using namespace std; #include <conio.h> //for getch() char ch = 'a'; //global variable ch void getachar();/* w ww.jav a 2 s . c o m*/ 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; }
#include <iostream> using namespace std; int g, h; // Global because they're defined before a function. int main()//from w w w. j av a 2 s.co m { // int main()'s code goes here. }