Concept of "auto" keyword in c
auto
isn't a datatype. It's a storage class specifier, like static
. It's basically the opposite of static
when used on local variables and indicates that the variable's lifetime is equal to its scope (for example: when it goes out of scope it is automatically destroyed).
You never need to specify auto
as the only places you're allowed to use it it is also the default.
It might be useful in C89 where you have an implicit int rule.
void f() {
a = 0; // syntax error
auto b = 0; // valid: parsed as declaration of b as an int
}
But then, you can just write straight int
instead of auto
. C99 doesn't have an implicit int rule anymore. So I don't think auto
has any real purpose anymore. It's "just the default" storage specifier.