dcsimg
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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