devxlogo

The auto Keyword

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];}size=3>

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];}size=3>

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;'size=3>

In those days, you could also write:

 auto n; // equivalent to 'auto int n'size=3>

However, standard C++ doesn’t permit declarations with implicit int anymore. Consequently, ‘auto’ has become completely optional.

devxblackblue

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.

About Our Journalist