Storage Classes in C

A storage class defines the scope, visibility and life-time of variables or functions within a C Program. Storage class help us to trace the existence of a particular variable during the runtime of a program.

We have four different storage classes in a C program :

  1. auto
  2. register
  3. static
  4. extern

  1. auto :
  2. The auto storage class is the default storage class for all local variables.

  3. register :
  4. The register storage class is used to define local variables that should be stored in a register instead of RAM.

  5. static :
  6. The static storage class instructs the compiler to keep a local variable in existence during the lifetime of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls.

  7. extern :
  8. The extern storage class is used to give a reference of a global variable that is visible to ALL the program files. When you use 'extern', the variable cannot be initialized, however, it points the variable name at a storage location that has been previously defined.

Post a Comment

0 Comments