Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

clrscr

Quick C++ question

This topic is 6180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what is the keyword auto used for? I haven''t been coding long, but I don''t think I''ve ever see it in use.

Share this post


Link to post
Share on other sites
Advertisement
Basically, auto means that the variable is going to be local; in other words, it will be created within its scope and destroyed when its scope goes away.

If you had:
  
float justDoIt()
{
auto float x, y, z;
...
return x*y*z;
}


Then the variables x, y, and z are created in the function and destroyed when the function returns.

They exist only in the body of the function in which the definition appears.

This type of automatic storage is a way to conserve memory since they are destroyed when they go out of scope.

The reason why you''ll probably never see this in anyone''s code is because it goes before all you variable declerations in a function as a default. I have rarely seen people use this keyword.

Good luck!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!