Can the auto
keyword be used as a storage class specifier in C++11?
Is the following code legal in C++11?
int main() {
auto int x;
}
The auto keyword directs the compiler to use the initialization expression of a declared variable, or lambda expression parameter, to deduce its type.
auto: This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language. Auto variables can be only accessed within the block/function they have been declared and not outside them (which defines their scope).
The initialization of these variables is, by default, a garbage value. The memory that is assigned to an automatic variable gets free when it exits from a block. We use the keyword auto to define the automatic variables.
Which of the following is not a storage class specifier in C? Explanation: volatile is not a storage class specifier. volatile and const are type qualifiers.
No the code is ill-formed in C++11. auto
in C++11 would be used to deduce the type of a variable from its initializer and it can't be used as a storage class specifier.
Correct Usage
int main()
{
auto x = 12; // x is an int
auto y = 12.3; // y is a double
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With