0
2.2kviews
What is significance of storage classes? Explain it with relevant example.

Subject : Structured Programming Approach

Title : Functions and Parameter

Difficulty : Medium

1 Answer
0
48views

The different locations in the computer where we can store data andtheir accessibility,initial values etc.very based on the way they are declared. These different ways are termed as different storage classes.

In C there are for storage classes,namely

1.Automatic

2.Register

3.Static

4.External or global

1.Automatic storage class: In this case data is stored in memory.The initial value of such a variable is garbage. The scope of the variable is local i.e.limited to the function in which it is defined.The life of such variables is till the control remains in the particular function where it is defined.

Example

Int i; or auto int i;

2.Register storage class: In this case data is stored in CPU register.The initial value of such a variable is garbage.The scope of the variable is local i.e.limited to the function in which it is defined. The life of such variables is till the control remains in the particular function where it is defined.

Example:

Register int I;

In this case the data is stored in a small memory inside the processor called its registers.

The advantage of such storage class is that since the data is in the processor itself,its access and operation on such data is faster.

There is limitation on the size of the data that can declared to be register storage class. The data should be such that it doesn’t require more than 4 bytes. Hence double and long double data types cannot be declared as a register.Also there is a limitation on the maximum number of variables in a function that can be a register class. The limitation is that a maximum of 3 register class variable can be declared in a function.

3.Static storage class: In this case data is stored in a memory.The initial value of such a variable is zero.The scope of the variable is local i.e. limited to the function in which it is defined.The life of such variable is till the program is alive.

Example:

Static int I;

If a variable is declared static,its value remains unchanged even If the function execution is completed.

When the execution to that function returns, the previous value is retained.

Thus it says the initialization is only once. If you have an initialization statement of a static member,it will be executed only once i.e. for the first time when this function is called.

4.External or global storage class: In this case data is stored in memory. The initial value of such a variable is zero.The scope of the variable is global i.e. it is accessible from anywhere in the program.The life such a variable is till the program is alive.

Please log in to add an answer.