I am aware that by default a variable will have auto
storage class. Then, can anyone explain me with an example where in my life i may need to explicitly specify auto keyword? If there is no such scenario, then why such a keyword is specified in the C language definition?
Asked
Active
Viewed 47 times
1

Hari Krishnan
- 5,992
- 9
- 37
- 55
-
Because of history and backcompat. – Tanveer Badar Jan 13 '20 at 10:12
-
1It's a good question. (It probably seemed like a good idea at the time particularly in the days of implicit `int`.) Hope the duplicate helps. (Note that in C++ `auto` has been repurposed.) – Bathsheba Jan 13 '20 at 10:13
-
"[A] variable" should really be "a *local non-static* variable", as `auto` have never made sense (or even worked?) on anything else. – Some programmer dude Jan 13 '20 at 10:14
-
https://stackoverflow.com/a/24314643/6266 seems like a reasonable explanation of the history – Fire Lancer Jan 13 '20 at 10:15
-
It's redundantly kinda like using unnecessary parenthesis in `auto double x;;;;; ... sizeof (x) ...` – pmg Jan 13 '20 at 10:16