Global Variables
If you write the statement
int gMoveNumber = 0;
at the beginning of your program—outside any method, class definition, or function—its value can be referenced from anywhere in that module. In such a case, we say that gMoveNumber is defined as a global variable. By convention, a lowercase g is commonly used as the first letter of a global variable, to indicate its scope to the program’s reader.
Actually, this same definition of the variable gMoveNumber also makes its value accessible from other files. Specifically, the preceding statement defines the variable gMoveNumber not just as a global variable, but as an external global variable.
An external variable is one whose value can be accessed and changed by any other methods or ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access