Specifying Types – Variables
As C++ is a statically typed language, it is necessary to specify the type of a variable when it is declared. When you declare a function, it is necessary to specify the return type and the types of arguments that are being passed to it. There are two choices for specifying the type to a variable when you declare it:
- Explicitly: You, as the programmer, are dictating exactly what the type is.
- Implicitly (using auto): You are telling the compiler to look at the value that was used to initialize the variable and determine its type. This is known as (auto) type deduction.
The general form of declaration for a scalar variable is one of the following:
type-specifier var; // 1. Default-initialized variable
type-specifier var = init-value; // 2. Assignment initialized...