What are the Storage Types for Variables in C++ ?

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

There are four different storage types for variables:

- Auto: An auto variable is a local scope variable whose lifetime contained within a function definition (or function block). All local variables are by default auto variables. These variables persist only until the end of the block in which they are defined.
- Static: a static variable is the one that retains its value between function calls.
- Global: A global object is a run-time entity that exists throughout the duration of the program. The lifetime of the storage in which a global object resides begins at program start-up and ends when the program terminates. It is defined outside any function.
- Extern: when variables need to be shared across files then one needs to declare them as external variables.
- Register: Like auto variables register variables also cease to exist at the end of the block. These variables are stored in the CPU register to minimize the time to red and write these variables to the memory. However declaring a variable as register is merely a request to the compiler.

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email