Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 272421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:18:45+00:00 2026-05-12T00:18:45+00:00

Note this question was originally posted in 2009, before C++11 was ratified and before

  • 0

Note this question was originally posted in 2009, before C++11 was ratified and before the meaning of the auto keyword was drastically changed. The answers provided pertain only to the C++03 meaning of auto — that being a storage class specified — and not the C++11 meaning of auto — that being automatic type deduction. If you are looking for advice about when to use the C++11 auto, this question is not relevant to that question.

For the longest time I thought there was no reason to use the static keyword in C, because variables declared outside of block-scope were implicitly global. Then I discovered that declaring a variable as static within block-scope would give it permanent duration, and declaring it outside of block-scope (in program-scope) would give it file-scope (can only be accessed in that compilation unit).

So this leaves me with only one keyword that I (maybe) don’t yet fully understand: The auto keyword. Is there some other meaning to it other than ‘local variable?’ Anything it does that isn’t implicitly done for you wherever you may want to use it? How does an auto variable behave in program scope? What of a static auto variable in file-scope? Does this keyword have any purpose other than just existing for completeness?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:18:45+00:00Added an answer on May 12, 2026 at 12:18 am

    auto is a storage class specifier, static, register and extern too. You can only use one of these four in a declaration.

    Local variables (without static) have automatic storage duration, which means they live from the start of their definition until the end of their block. Putting auto in front of them is redundant since that is the default anyway.

    I don’t know of any reason to use it in C++. In old C versions that have the implicit int rule, you could use it to declare a variable, like in:

    int main(void) { auto i = 1; }
    

    To make it valid syntax or disambiguate from an assignment expression in case i is in scope. But this doesn’t work in C++ anyway (you have to specify a type). Funny enough, the C++ Standard writes:

    An object declared without a storage-class-specifier at block scope or declared as a function parameter has automatic storage duration by default. [Note: hence, the auto specifier is almost always redundant and not often used; one use of auto is to distinguish a declaration-statement from an expression-statement (6.8) explicitly. — end note]

    which refers to the following scenario, which could be either a cast of a to int or the declaration of a variable a of type int having redundant parentheses around a. It is always taken to be a declaration, so auto wouldn’t add anything useful here, but would for the human, instead. But then again, the human would be better off removing the redundant parentheses around a, I would say:

    int(a);
    

    With the new meaning of auto arriving with C++0x, I would discourage using it with C++03’s meaning in code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This question has been originally posted by Lahiru Gunathilake as an answer to
NOTE : This question was originally asked way back in 2012. Before the decltype
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
Note: I posted a similar question , which was the ancestor of this question,
Note: This question originally applied to Xapian , but due to cross-platform issues and
Last Updated: 2009-08-11 2:30pm EDT A few days ago I posted this question about
Note: This question was originally part of Magento SOAP API V2 with C#: Issue
NOTE: I have updated this since originally asking the question to reflect some of
Note This originally started as a question about 404 errors, but now it's a
Based on the first two answers, the question was unclear as originally posted, thus

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.