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 ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.