Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

C%20%20%20Interview%20Questions%20and%20Answers

Question: What?s the auto keyword good for?
Answer:
Answer1
Not much. It declares an object with automatic storage duration. Which means the object will be destroyed at the end of the objects scope. All variables in functions that are not declared as static and not dynamically allocated have automatic storage duration by default.

For example
int main()
{
int a; //this is the same as writing ?auto int a;?
}

Answer2
Local variables occur within a scope; they are ?local? to a function. They are often called automatic variables because they automatically come into being when the scope is entered and automatically go away when the scope closes. The keyword auto makes this explicit, but local variables default to auto auto auto auto so it is never necessary to declare something as an auto auto auto auto.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook