Automatic variable: Difference between revisions

Content deleted Content added
Reverted 1 edit by Kali yadav (talk): Looks like nonsense. (TW)
MCWNT (talk | contribs)
C, C++: Removed dead example, the auto keyword cannot anymore be used like that.
Tags: Mobile edit Mobile web edit
Line 12:
(Called ''automatic'' variables.)
 
All variables declared within a [[block (programming)|block]] of code are automatic by default, but this can be made explicit with the <code>auto</code> keyword.<ref group="note">recent C++ standards, specifically [[C++11]] and later, change the meaning of the <code>auto</code> keyword, using it for [[type inference]] and an alternate function declaration syntax.</ref> An uninitialized automatic variable has an [[undefined behavior|undefined]] value until it is assigned a valid value of its type.<ref>{{As of|2008|alt=Current}} {{PDFlink|[http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf C standard]|3.61&nbsp;[[Mebibyte|MiB]]<!-- application/pdf, 3788603 bytes -->}}: section 6.2.4, Storage durations of objects</ref>
 
Using the storage class <code>register</code> instead of <code>auto</code> is a hint to the compiler to cache the variable in a processor register. Other than not allowing the referencing operator (<code>&</code>) to be used on the variable or any of its subcomponents, the compiler is free to ignore the hint.