What is the exact concept of the keyword auto in a C program?
When I went through the book Deep C secrets, I saw this quote:
The
autokeyword is apparently
useless. It is only meaningful to a
compiler-writer making an entry in a
symbol table. It says this storage is
automatically allocated on entering
the block (as opposed to global static
allocation, or dynamic allocation on
the heap). Auto is irrelevant to
other programmers, since you get it by
default.
autoisn’t a datatype. It’s a storage class specifier, likestatic. It’s basically the opposite ofstaticwhen used on local variables and indicates that the variable’s lifetime is equal to its scope. When it goes out of scope it is "auto"-matically destroyed.Note that
autoin C is currently (ie: in C17 and earlier) not likeautoin modern C++ — it does not perform any type inference. However, it is possible that C23 will changeautoto do a weaker form of type inference. Theautokeyword is pretty useless today: you never need to specify it as the only places you’re even allowed to are exactly the places where automatic storage is already the default behavior.