Declarations without a type

C++11 introduces a mechanism for declaring that a variable's type should be determined from the data it is initialized with, that is, auto.

There is a minor confusion here because prior to C++11, the auto key was used to declare automatic variables, that is, variables that are automatically allocated on the stack in a function. Other than variables declared at file scope or as static, all the other variables in this book so far have been automatic variables and automatic variables are the most widely used storage class (explained shortly). Since it was optional and applicable to most variables, the auto keyword was rarely used in C++, so C++11 took advantage of this, removed the old meaning, and gave auto a new ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.