Storage Class
1. What are defined in the storage class?
Ans: The life time and scope of the variable or/and function in a program are defined in the storage
2. List the storage classes supported by C.
Ans: C supports the following storage classes and the corresponding C keywords associated with
them are as follows:
Storage class Keyword
1. Automatic auto
2. External extern
3. Static static
4. Register register
3. Give the importance of storage class.
Ans: The storage class of a variable tells the compiler:
1. The storage area or scope of the variable.
2. The initial value of variable if not initialized.
3. The scope of the variable.
4. Life of the variable, i.e., how long the variable would be active in the program.
4. What does scope of the variable mean?
Ans: Area or the scope, where the variable is to be accessed. Some variables are global and can
be accessed anywhere in the program, whereas some variables scope is in the block where they are
declared. This area is local for them.
5. What are the auto variables?
Ans:  The variables that are available only to the current block or program are auto variables.
The auto variables are stored in the main memory of the system. By default, the storage class of
variables is auto.
M11_ITL-ESL4791_02_SE_C11.indd 236 12/22/2012 5:05:15 PM
Storage Class II-237
6. What are the additional uniqueness of auto variables?
1. The auto variables are defined inside a function. The keyword auto should only be used within
the function.
2. The scope of the auto variables is local to the block in which they are defined. Once the execu-
tions of the function take place and return turns off the function, the contents and existence of the
auto variables or local variable vanishes.
3. The auto variables are stored in the main memory. They are stored in the stack at run time.
4. The keyword 'auto' is used for declaration of automatic variables. By default, every variable
pertains to auto storage class. The 'auto' is optional.
7. Write a program on auto variables.
void main()
auto int b=7;
int c=5;
printf("\n %d %d",b,c);
auto int b=10;
printf("\n %d",b);
printf("\n %d",b);
7 5
Explanation: In the above program, declaration and initialization of b is made two times with different
values. In the first block, the b value is 7 and in second block its value is 10. Before passing control to
the second block, the value of b variable printed is 7 and after passing control to the second block, the
value of b is changed to 10. By default, the storage class for c is auto.
8. What are the register variables?
Ans: The 'register' variables are stored in the registers of the CPU. Accessing variables through
the register of the CPU is faster than the memory access.
9. Give the characteristics of register variables.
1. Speed of execution of program is fast because variables are stored in CPU register. Accessing
variables through the CPU register is faster than RAM. The keyword register tells the compiler
that the variable list followed by it is kept on the CPU registers.
M11_ITL-ESL4791_02_SE_C11.indd 237 12/22/2012 5:05:15 PM

Get Express Learning - Computer Fundamentals and Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.