what is the extent of an identifier. What code can see/use/access it?
- Formal arguments and local variables are visible/accessible only within that function.
Can't "look inside" another function (including main)
- Global variables (declared outside any function) accessible to all.
Can "look outside" of function to the global space. Not allowed in
this course so to enforce learning of argument passing and good
programming practices!
- Local declaration overrides a global declaration.
int c; //global
int main() {
int m, a;
..// can access locals m and a and global c
}
int f1 (int x) {
int a;
..// can access local x and a, and global c
}
int f2 (int y) {
int a,b,c;
..// can access local y, a, b, and c; can not access global c
}
Function names are global. Thus any function can "see" all
other functions in the file and call them.
Next (function examples)
©David Wills