devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.