Is auto ever useful in C/C++?

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.


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.


In GCC you might need auto to declare nested function in order to be able to define it anywhere in function body - see http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Nested-Functions.html