Local variable: Difference between revisions

Content deleted Content added
Static local variables: clarify static local meaning
Line 8:
 
==Static local variables==
A special type of local variable, called a ''static local,'' is available in many mainstream languages (including [[C (programming language)|C]]/[[C++]], [[Visual Basic]], and [[Visual Basic .NET|VB.NET]]) which allows a value to be retained from one call of the function to another – it is a [[static variable]] with local scope. In this case, recursive calls to the function also have access to the (single, [[static memory allocation|statically allocated]]) variable. In all of the above languages, static variables are declared as such with a special ''storage class'' keyword (e.g., <code>static</code>).
 
Static locals in global functions have the same lifetime as [[static global variable]]s, because their value remains in memory for the life of the program,<ref>{{PDFlink|[http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf Current C standard]|3.61&nbsp;MB<!-- application/pdf, 3788603 bytes -->}} ({{As of|2009|lc=on}}). In particular, see section 6.2.4 “Storage durations of objects”, page 32.</ref> but have [[function scope]] (not global scope), as with automatic local variables.