Sunday, August 07, 2005

static variable

The static keyword allows a variable to maintain its value among different function calls. If the value of a static variable changes when the variable has been accessed, the variable keeps the new value. If the same variable gets accessed again, it would be holding its most recent value. This is possible because, when the static variable is declared, the compiler uses a separate memory area to store it. By doing this, when the value of the static variable gets changed, it is updated in the memory it is occupying. And because this memory is separate, the compiler can monitor its values even when its function exits.

No comments:

Post a Comment