Static variable: Difference between revisions

Content deleted Content added
Corto (talk | contribs)
mNo edit summary
Line 9:
==Static Variables as Local Function Variables==
 
Most programming languages include the concept of [[functions]] (also known as [[methods]] or [[procedures]]). These structures resemble smaller programs that can be ''called'' as subtasks from the main application, or even from other subtasks. Functions simply perform their intended operation and return control to the caller. Usually, any [[local variablesLocal_variable|variables local to the function]] (or [[function variables]]) are created and destroyed within the function itself.
 
Some languages allow functions to ''retain'' the value of variables between calls, so that the function can preserve its [[state]] if necessary. For example, with a static variable a function could record the number of times it has been executed using an internal counter. This would only otherwise be possible using [[global variables]] or an external storage method, like a file on disk.