| types/scope-prog.c - Illustration af basale scoperegler. | Lektion 8 - slide 20 : 29 Program 1 |
/* We care about the scope of f, local and g.
The program also illustrates a couple of scope-related problems */
#include <stdio.h>
void f(int a); /* Scope of f includes main */
int main(void) {
double local = 5.1; /* Scope of local is the main block */
f(4);
g(local, 6.0F); /* ERROR: The scope of g does not include this point */
return 0;
}
void f(int arg){
int local = 6; /* The scope of local is the block of f */
f(arg - local); /* OK - both f, arg, and local are in scope */
}
void g(double f, float arg){
f(5); /* ERROR: The scope of the function f */
/* does not include this point. */
/* Hole in the scope of function f */
}