1.

Write About C++ Storage Classes?

Answer»

The STORAGE classes are qualifiers that are used to specify the lifetime of a variable. The lifetime of a variable relates to the portion of the program that has ACCESS to the variable. Storage CLASS directs the compiler about how to store the variable in memory and how to access variable within the program.
The following are the different types of storage classes:

  •  Auto —Identifies the local variable as AUTOMATIC, which means that each invocation of the statement block in which the variable is defined gets a fresh copy with its own memory space and with re-initialization each time.
  •  Static —Refers that the scope of a static local variable begins inside the statement block in which the variable is declared and ends when the block terminates. The variable itself retains its value between executions of the statement block.
  •  Extern —Declares a global variable in ONE program that can be accessed by another program. The default value of an extern variable is zero. This variable is useful in a scenario where we divide one large program into different small programs and use external variable in each small program. The main advantage of using external variable is that the complexity of a program can be reduced by separating a large program into smaller programs and using external variable, which is shared by all the programs.
  •  Register —Refers that a variable declared with the register storage class is the same as an auto variable except that the program cannot take the variable's address. Its purpose is to allow the programmer to specify conditions under which the program's performance would be improved if certain local and automatic variables were maintained in one of the computer's hardware registers.

The storage classes are qualifiers that are used to specify the lifetime of a variable. The lifetime of a variable relates to the portion of the program that has access to the variable. Storage class directs the compiler about how to store the variable in memory and how to access variable within the program.
The following are the different types of storage classes:



Discussion

No Comment Found