Note this question was originally posted in 2009, before C++11 was ratified and before the meaning of the
autokeyword was drastically changed. The answers provided pertain only to the C++03 meaning of
auto— that being a storage class specified — and not the C++11 meaning of
auto— that being automatic type deduction. If you are looking for advice about when to use the C++11
auto, this question is not relevant to that question.
For the longest time I thought there was no reason to use the
static keyword in C, because variables declared outside of block-scope were implicitly global. Then I discovered that declaring a variable as
static within block-scope would give it permanent duration, and declaring it outside of block-scope (in program-scope) would give it file-scope (can only be accessed in that compilation unit).
So this leaves me with only one keyword that I (maybe) don't yet fully understand: The
auto keyword. Is there some other meaning to it other than 'local variable?' Anything it does that isn't implicitly done for you wherever you may want to use it? How does an
auto variable behave in program scope? What of a
static auto variable in file-scope? Does this keyword have any purpose other than just existing for completeness?