Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is auto ever useful in C/C++?

Has anyone ever seen the storage class auto explicitly used in C/C++? If so, in what situation?

like image 700
c0m4 Avatar asked Oct 31 '08 05:10

c0m4


2 Answers

auto is never useful in current C/C++ because all variables are implicitly auto. It is useful in C++0x, where it can replace the type declaration entirely - if you have a variable with an initial assignment, 'auto' will just make it the type of that assignment value, as in the comments.

like image 146
alex strange Avatar answered Sep 22 '22 06:09

alex strange


I haven't seen auto used in code written in the last 10+ years. There is no reason to use auto since the only places you can use it is where it is implied anyway. The only reason it still exists is for backwards compatibility but it should be avoided in new code.

like image 40
Robert Gamble Avatar answered Sep 26 '22 06:09

Robert Gamble