10 Question of the Storage Class in C Language free

1 Ques: – What are storage classes in the C language?

The Storage Class of a variable tells us about (characteristics of storage classes).

  1. Storage place of the variable i.e. Memory or CPU registers.
  2. The initial value of the variable, if it is not specified in the program.
  3. The scope or the visibility of the variable.
  4. The lifetime of the variable i.e. how long the variable exists.

2 Ques: – How many Storage classes in the C language?

There are Four Types of Storage Classes in C Language,

  1. Automatic Storage Class (with specifier auto)
  2. Register Storage Class (with specifier register)
  3. Static Storage Class (with specifier static)
  4. External Storage Class (with specifier extern)

3 Ques: – Difference Between Local and Global Parameters.

Local Parameters Global Parameters
A variable which is defined in-side a function is known as local parameter.A variable which is defined outside all functions are called global variables or parameters.
Local Parameters are also called as internal parameters.Global parameters are also called as external variables.
The scope of local parameters is limited to the function in which they are declared.The scope of Global parameters is throughout in the program.
The memory is allocated to local variables each time, the control enters the function and released when the control leaves the funciton.Global parameters remain in memory throughout the execution of the program.
Local Parameters can be accessed within the only function in which they are defined.Global parameters can be accessed in any of the functions in a program.
They can be used with automatic, static and register storage class.They can be used with external storage class only.

4 Ques: – Explain the need of external variables.

External variables are declared outside all function i.e. at the beginning of the program. When the size of the program becomes very large then if has to be divided into parts and each part is stored in a separate function. Global variables should be available to all the functions with the help of extern specifier.

5 Ques: – Explain Rules of use Storage Classes in C.

  1. Use static class only if you want the value of a variable to persist between function calls.
  2. Use register storage class for only those variables which are being used very often. e.g. loop counter.
  3. Here Use External Storage class for only those variables which are being used by almost all the functions in the program.
  4. Finally in all other situations go ahead using automatic types of storage class.
Storage Class - E-Books

6 Ques: – Which storage class to use and when?

The Programmer can decide as his/her own that which storage class has to be used and when, according to the requirements in a program. He can use appropriate storage class by following the views for usage of different storage class in different situations.

  1. Economies the memory space requirements consumed by the variables.
  2. Improve the speed of execution of the program.

7 Ques: – Difference Between Automatic and Register Storage Class.

DifferenceAutomaticRegister
Storage MemoryCPU registers
Default Initial ValueGarbage value i.e. an unpredictable value.Garbage Value
ScopeLocal or visible to the block in which variable is declared e.g. if the variable is declared in a function then it is only visible to the function.Local to the block in which variable is declared (same as automatic).
LifetimeIt retains its value till the control remains in the block in which the variable is declared. e.g. if the variable is declared in a function , it will retain its value till the control is in that function.It retains its value till the control remains in the block in which the variable is declared. (same as automatic)

8 Ques: – What Variable Storage Class can tell us.

A variable Storage Class can tell us,

  1. The place where the variables may be stored.
  2. The initial value of the variables.
  3. Visibility i.e. which part of a program can access the varaibles.
  4. Lifetime how long the variable stays in memory.

9 Ques: – Name Storage Classes with Keywords and simple one line Example.

Storage ClassesKeywordExample
Automaticauto auto int a, b,c;
External externextern float a, b;
Static staticstatic int i =0;
Register registerregister char ch;

10 Ques: – Difference Between Static and External variables.

StaticExternal
The default initial value of static variable is zero.The default initial value of external variables is zero.
In case of static variables, the value of variables persist between different function calls. In case of external variables it retains its value throughout the program.
Automatic variable is used auto key-External variables use extern keyword word.
Example of automatic variable declaration is auto int i; Example of external variable is extern int i;
The keyword static is compulsory if we want to declare static variables. The extern keyword is optional if we want to declare external variables before any function.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top