0

Possible Duplicate:
Is there any reason to use the ‘auto’ keyword in C / C++?

can anybody explain me purpose of auto keyword in c++? thanks

Community
  • 1
  • 1
  • 6
    Can you consider buying a book on C++? And how about learning to search SO? –  Jul 12 '10 at 09:13
  • google 'auto keyword c++', first hit: http://msdn.microsoft.com/en-us/library/6k3ybftz(VS.80).aspx, which says it's redundant and means the same as stating no storage class as all (which you usually don't) – falstro Jul 12 '10 at 09:14
  • Related question: http://stackoverflow.com/questions/2192547/where-is-the-c-auto-keyword-used – sharptooth Jul 12 '10 at 09:16
  • 1
    The above mentioned question convers the usage of 'auto' in C. Question is about C/C++. The meaning of 'auto' in C++ recently changed with the upcoming c++0x standard, which indeed gives 'auto' a new, very respectable and useful role. UPDATE: The "Possible Duplicate" Question mentions the new usage of auto. – Nordic Mainframe Jul 12 '10 at 09:25

1 Answers1

0

It's useless and is left for old code compatibility. Long ago you used it to say that a variable is automatic, this is no longer useful - all variables witout other qualifiers are treated as automatic (stack-allocated).

sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • 1
    Actually, as of C++0x, auto has been moved back into the spotlight. It's now used for automatic type inference, quite like var in C#. E.g. auto it = myvec.begin(); – Andreas Magnusson Jul 12 '10 at 10:40