liveBook · Manning

Auto

auto is a language feature that directs the compiler to deduce an object's type from its initializer.

How 3 Manning books explain it

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.

Read how Learn C++ by Example explains auto →

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.

Read how Modern C, Third Edition explains auto →

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
Simplifies variable and iterator declarations by letting the compiler infer types from initializers.
How deep it goes
Explains deduction in loops and iterator declarations, then warns that unsigned deduction can break countdown loops.
Examples
Contrasts an index loop and std::find iterator using auto with an unsafe reverse loop.
What you can do after
Diagnose when deduction helps and when an explicitly signed loop variable avoids unsigned underflow.

Read how 100 C++ Mistakes and How to Avoid Them explains auto →

What to know first

Related concepts

Questions about auto

What is auto?

auto is a language feature that directs the compiler to deduce an object's type from its initializer.

Which Manning books explain auto?

Learn C++ by Example, Modern C, Third Edition and 100 C++ Mistakes and How to Avoid Them.

What should I know before learning auto?

Manning books that teach auto usually introduce iterator and range-based for loop first.

What is the difference between auto and C23?

auto is a language feature that directs the compiler to deduce an object's type from its initializer. C23 is the ISO standard revision of the C programming language published in 2024.

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.