// HINTS5.cpp. Illustration of side effects with // global variable #include using namespace std; int globalVar; // POOR DESIGN: a global variable int main() { void tripleGlobalVar(); void displayGlobalVarTensDigit(); globalVar = 125; cout << "The tens digit is "; displayGlobalVarTensDigit(); tripleGlobalVar(); cout << " ,but the tens digit of the triple is "; displayGlobalVarTensDigit(); cout << "." << endl; return 0; } // // This routine triples the global variable globalVar // void tripleGlobalVar() { globalVar = 3 * globalVar; } // // This routine displays the tens digit of globalVar and // produces a side effect // void displayGlobalVarTensDigit() { globalVar = (globalVar / 10) % 10; // SIDE EFFECT cout << globalVar; }