CSC209H1 Lecture Notes - Include Directive, Global Variable, External Variable
Document Summary
To access it in another file, need to do something special. Unlike variables on the stack that"s available only while the function it"s declared in is on the stack: static variables. Static used outside a (function) block means that the variable is only visible in the file in which it is declared (file scope) Used to limit the visibility of the variables. Static used in a (function) block means that the variable lives beyond the duration of the (function) block and is initialized only once, ex. Int q is in memory only in the duration of the function f, it will always be initialized with the value -1. Int j only gets initialized once, on the next function call j will retain its previous value static int i; // outside a block void f(void) { int q = -1 static int j; // inside a block.