auto Automatic storage duration specifier

auto Automatic storage duration specifier

auto gives locals automatic storage, their C89 default. Each block or recursive entry creates objects; file scope is invalid, and modern C often omits it.

CategoryStorage-class specifiers
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

auto int x = 0;  /* Equivalent to int x = 0; */

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

block value = 1
block value = 1

📚 Related Tutorials

❓ FAQ

QIs auto int different from a plain local int?
ANo. Where auto is permitted in a block, auto int and int have the same automatic storage duration and runtime behavior, so modern C normally omits auto.
QCan auto qualify a global variable?
ANo. auto is limited to block-scope objects with automatic storage duration and related declaration contexts. File-scope objects have static storage duration and cannot use it.
QIs an auto variable in a loop recreated on every iteration?
AIf its declaration is inside the loop body, each entry into that block begins a new lifetime and runs the initializer. An object declared outside the loop persists across iterations; auto does not imply zeroing.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏