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.
| Category | Storage-class specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / 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 storage-class specifiers
📚 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.