-
Notifications
You must be signed in to change notification settings - Fork 0
section6_external_variables
A C program consists of externel objects which are either variables or functions. Internal variables are function parameters or variables defined inside functions, which are not visible elsewhere.
void foo() {
int a;
}
void goo() {
int a;
}
In the example above, both functions define a variable a
, however they are different. Each is only visible inside the function they belong to.
External variables, in contrast to internal ones, are defined outside of any function, thus available to many functions. Functions are also always external in this sense, because a function can't be defined inside another function, so functions scope is always global. External variables and external functions have the property that all references to them by the same name are references to the same thing, they are globally accessible.
In the previous section the functions' arguments were covered, and it seemed the only way to communicate data between functions. However, global variables provide an alternative way to achieve this communication. When the same piece of data is shared between several functions, this might be best approach. Nonetheless, use this "feature" with caution. Global variables have bad effects on the progream structure.
Another important characteristic regarding external variables is it's lifespan. Variables declared inside a function are called automatic, because they come into existence when the function is called and it's destroyed when the function terminates/returns. External variables, on the other hand, are permanent during the program lifespan.
Soon...