This is a simple example that does not really do much, other than illustrating the nature of local variables.
trace | A | B | C | D | explanation |
line# | y | “y” is a global variable, it exists as soon as the program starts to execute, and it only ceases to exit when the program ends. |
|||
pre | ? |
|
|||
6 | 2 |
| |||
7 | retline# | x | When we allocate a column for “retline#”, we also allocate a column for each local variable of the subroutine being invoked. |
||
post | ? | A local variable starts with an unknown value. |
|||
3 | 2 | There are two important points here. First, the global variable “y” is accessible in the subroutine. Second, a local variable can start values. |
|||
4 | 3 |
| |||
5 | retline# | x | At the end of a subroutine, when the “retline#” column is deallocated, all local variables should be deallocated as well. This means that the local variable “x” is not only invisible after this point, it actually does not even exist! |
||
post |
|
||||