Automatic variable
An automatic variable is a variable whose value, behavior, or lifetime is managed implicitly by a programming language or shell rather than controlled entirely by the programmer.
Modern C
An automatic variable is a C variable whose storage is created on entry to its enclosing block and released when execution leaves that block.
- How it is used
- Explains local object lifetime and initialization, including the effects of recursion and control flow.
- How deep it goes
- Develops block-lifetime rules and a compound-literal example, then illustrates an unoptimized machine setup; distinguishes VLA and temporary-object exceptions.
- Examples
- Uses a repeated compound literal with goto and compares its behavior with an assembler-level function setup.
- What you can do after
- Evaluate and understand when ordinary automatic objects exist, and distinguish their lifetime from initialization.
Modern C, Third Edition
An automatic variable is a C object with automatic storage duration, normally created on entry to a block and destroyed on exit from it.
- How it is used
- Uses automatic objects for block-local data and as a preferred way to work with local data in threads.
- How deep it goes
- Explains block lifetime, recursion, initialization, compound literal identity, and an illustrative machine model, while distinguishing variable-length arrays and temporary objects.
- Examples
- Uses a goto loop over a compound literal and corresponding unoptimized and optimized assembler listings.
- What you can do after
- Evaluate automatic-object lifetime and identity in block and recursive execution, including repeated evaluation of a compound literal.
Read how Modern C, Third Edition explains automatic variable →
What to know first
- command-line argumentA command-line argument is a value or option supplied to a program when it is invoked, providing input or affecting its behavior.
- compound literalA compound literal is a C expression consisting of a parenthesized type name followed by an initializer that creates an unnamed object.
- objectAn object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
- referenceA reference is an indirect value, binding, or relationship that identifies or provides access to another object, value, resource, or source.
Related concepts
- recursionproduced by · Recursion is a computational technique in which a definition or procedure refers to or invokes itself, directly or indirectly.
- lifetimeuses · A lifetime is the interval during which a program entity exists and remains valid or accessible under the applicable language rules.
- objectkind of · An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
- stackpart of · A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
Questions about automatic variable
What is automatic variable?
An automatic variable is a variable whose value, behavior, or lifetime is managed implicitly by a programming language or shell rather than controlled entirely by the programmer.
Which Manning books explain automatic variable?
Modern C and Modern C, Third Edition.
What should I know before learning automatic variable?
Manning books that teach automatic variable usually introduce command-line argument, compound literal, object and reference first.
What kinds of automatic variable are there?
Kinds of automatic variable include $Error.
What is automatic variable a kind of?
Automatic variable is a kind of object. An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
What is automatic variable part of?
Automatic variable is part of stack. A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

