Auto
auto is a language feature that directs the compiler to deduce an object's type from its initializer.
Learn C++ by Example
Auto type deduction is the C++ language feature that lets the compiler infer a variable's type from its initializer.
- How it is used
- Uses type deduction to simplify variables, range-based loops, container code, generic addition, and selected function declarations.
- How deep it goes
- Explains deduction through expressions, containers, iterators, templates, and return types, while deferring fuller lambda and closure treatment.
- Examples
- Demonstrates arithmetic promotion, std::plus, vector iteration, Pascal's triangle, nested-vector returns, and generic lambdas.
- What you can do after
- Apply auto to simplify container programs, generic functions, range loops, and deduced function returns.
Modern C, Third Edition
auto is a C23 type-inference feature that allows an object's type to be inferred from its initializer.
- How it is used
- Supports type-generic declarations whose types must follow initializer expressions, especially inside macros and library-result handling.
- How deep it goes
- Explains initializer-based inference through SWAP and div examples, but does not enumerate the complete declaration constraint set.
- Examples
- Uses inferred arithmetic variables, a generic SWAP macro, and a div result exposing quotient and remainder members.
- What you can do after
- Apply it to maintain type consistency in generic declarations and to capture structure-valued results without spelling their types.
100 C++ Mistakes and How to Avoid Them
auto is a C++ declaration specifier that asks the compiler to deduce a variable's type from its initializer.
- How it is used
- Uses type inference to simplify variable, iterator, and loop declarations in modern C++.
- How deep it goes
- Explains initializer-based deduction and a signedness failure, but does not develop deduction rules beyond these practical cases.
- Examples
- Uses index loops, vector searches, iterator declarations, reverse iteration, and references returned from student names.
- What you can do after
- Evaluate/understand when deduction improves declarations and when an explicitly signed counter prevents unsigned wraparound.
Read how 100 C++ Mistakes and How to Avoid Them explains auto →
Related concepts
- C23contrasts with · C23 is the ISO standard revision of the C programming language published in 2024.
- type inferenceimplements · Type inference is the automatic deduction of program or expression types from available values, context, and constraints without requiring explicit type annotations.
- typeof operatoralternative to · A typeof operator obtains type information about an operand or expression, yielding a type or a string describing its type depending on the language.
- compileruses · A compiler is software that translates source code into executable code or another representation, while analyzing it according to the source language’s rules.
- trailing return typeuses · A trailing return type is C++ syntax that places a function's return type after its parameter list using an arrow.
- functionconfigures · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
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.


