User Tools

Site Tools


guides:programstyle:globals

This is an old revision of the document!


Global Variables

Global variables are variables that are declared outside the scope of a function. While it is common, even encouraged, to declare global constants, global variables are problematic as program size increases. Because of this, the use of global variables should be limited.

#include <iostream>
 
using namespace std;
 
// count is a global variable.  This should be avoided.
int count;
 
// MAX_SIZE is a global constant.  This is not a problem.
const int MAX_SIZE;
 
int main() {
  ...
}

You should not use global variables unless you are given permission to do so by your instructor.

guides/programstyle/globals.1659441553.txt.gz · Last modified: 2022/08/02 11:59 by 127.0.0.1