In C, why we go for storage classes? I heard that auto type is the same as the local variable. in that case, why we go for auto type?is there any special by using auto type instead of local variables which is not mentioned as auto. for example,
int a=10;
and
auto int a=10;
both are stored in stack segment and scope of these variables is within the function.so what is the difference between these two? why we go for auto
-type?
First of all,
auto
(keyword) is not a type specifier, it's a storage class specifier. Quoting from the standard,To quote
C11
, chapter ยง6.2.4, Storage durations of objectsand, regarding the linkage, (emphasis mine)
So, local variables, satisfying above conditions are by default, having automatic storage duration. You don't have to explicitly specify the
auto
keyword.OTOH, type-specifiers determine the type (of data or variables). Going by the standard definition of type