|
|
Function Variables |
|
Discussed variables the first week of class
All variables exist for the duration of their scope and can only be accessed within their scope.
Anything defined outside of a set of curly braces is in global scope.
All functions can see and modify global variables.
The following program manipulates a global variable
int x = 5;
void func1 () { x = 1; }
void func2 () { printf("%d\n", x); }
int main () {
func1();
func2();
return (0);
}
Global variables are normally considered bad practice if they can at all be avoided as it makes debugging difficult.