Storage class is used to declare the lifetime and visibility of a variable and/or function within a program scope.
C++ offers four types of storage classes:
- Automatic -default storage class for all local variables. The auto keyword is applied to all local variables automatically.
- Register - The register variable allocates memory in register than RAM. Its size is same of register size. It has a faster access than other variables.
- Static - The static variable is initialized only once and exists till the end of a program. It retains its value between multiple functions call. Default value is 0.
- External - The extern variable is visible to all the programs. It is used if two or more files are sharing same variable or function.