What are the Storage Types for Variables in C++ ?
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.
