next up previous contents
Next: The Syntax Up: Local Variables Previous: Local Variables   Contents

The Concept

The concept of local variables is rather simple: a local variable is local to a particular subroutine. There are actually two aspects of being ``local''.

The first aspect of ``local'' is the scope. Recall that the scope of a name is defined by which part of the program can see it. A local variable has a local scope, which means it can only be seen (accessed) from the subroutine that defines it.

The second aspect of ``local'' is lifespan. In Pascal, all local variables start to exist when the containing subroutine is invoked, and they all cease to exist when the subroutine returns. In other languages like C and C++, you can specify a persistent lifespan for local variables.



Tak Auyeung 2003-12-03