- 1 Ques: – What are storage classes in the C language?
- 2 Ques: – How many Storage classes in the C language?
- 3 Ques: – Difference Between Local and Global Parameters.
- 4 Ques: – Explain the need of external variables.
- 5 Ques: – Explain Rules of use Storage Classes in C.
- 6 Ques: – Which storage class to use and when?
- 7 Ques: – Difference Between Automatic and Register Storage Class.
- 8 Ques: – What Variable Storage Class can tell us.
- 9 Ques: – Name Storage Classes with Keywords and simple one line Example.
- 10 Ques: – Difference Between Static and External variables.
1 Ques: – What are storage classes in the C language?
The Storage Class of a variable tells us about (characteristics of storage classes).
- Storage place of the variable i.e. Memory or CPU registers.
- The initial value of the variable, if it is not specified in the program.
- The scope or the visibility of the variable.
- 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,
- Automatic Storage Class (with specifier auto)
- Register Storage Class (with specifier register)
- Static Storage Class (with specifier static)
- 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.
- Use static class only if you want the value of a variable to persist between function calls.
- Use register storage class for only those variables which are being used very often. e.g. loop counter.
- Here Use External Storage class for only those variables which are being used by almost all the functions in the program.
- Finally in all other situations go ahead using automatic types of storage class.
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.
- Economies the memory space requirements consumed by the variables.
- Improve the speed of execution of the program.
7 Ques: – Difference Between Automatic and Register Storage Class.
Difference | Automatic | Register |
---|---|---|
Storage | Memory | CPU registers |
Default Initial Value | Garbage value i.e. an unpredictable value. | Garbage Value |
Scope | Local 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). |
Lifetime | It 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,
- The place where the variables may be stored.
- The initial value of the variables.
- Visibility i.e. which part of a program can access the varaibles.
- Lifetime how long the variable stays in memory.
9 Ques: – Name Storage Classes with Keywords and simple one line Example.
Storage Classes | Keyword | Example |
---|---|---|
Automatic | auto | auto int a, b,c; |
External | extern | extern float a, b; |
Static | static | static int i =0; |
Register | register | register char ch; |
10 Ques: – Difference Between Static and External variables.
Static | External |
---|---|
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. |
I read this piece of writing fully about the comparison of latest and previous technologies, it’s awesome article.