Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: All
Sep 4, 2001

The auto Keyword


'auto' is undoubtedly the least used C++ keyword. This is because it's always redundant. auto indicates local automatic storage type, for example:
 
int main()
{
 auto int x;
 auto char  s[10];
}

The more common form of declaring x and s is:
 
int main()
{
 int x; // identical to auto int x;
 char  s[10]; // identical to auto char  s[10];
}

Thus, 'auto' simply documents more explicitly the storage type of an object but it's never really needed. In pre-standard C++, the default type of incomplete declarations such as the following was int:
 
volatile x; // construed as 'volatile int x;'
const y  = 0; // construed as 'const int y=0;'

In those days, you could also write:
 
auto n; // equivalent to 'auto int n'

However, standard C++ doesn't permit declarations with implicit int anymore. Consequently, 'auto' has become completely optional.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date