What are different storage classes in C++?

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:

  1. Automatic -default storage class for all local variables. The auto keyword is applied to all local variables automatically.
  2. 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.
  3. 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.
  4. External - The extern variable is visible to all the programs. It is used if two or more files are sharing same variable or function.