Program: 141
Write a C program to show the storage, default initial value, scope and life of register storage class variables.
Variable Storage Class tells us:
- Storage (location)
- Default Initial Value of the variable
- Scope of the variable
- Life of the variable
1. Storage: Where the variable would be stored.
2. Default Initial Value: What will be the initial value of the variable, if initial value is not specifically assigned. (i.e. the default initial value)
3. Scope: What is the scope of the variable: i.e. in which functions the value of the variable would be available.
4. Life: What is the life of the variable: i.e. how long would the variable exist.
Register Storage Class:
Same as Automatic Storage Class but uses registers instead of memory.
Storage : CPU Registers
Default Initial Values : A garbage Value (unpredictable value)
Scope : Local to the block remains within the block in which the variable defined.
Life : Till the control remains within the block in which the variable is defined.
Note: We can’t say for sure that the value of register class variables would be stored in a CPU register, because the number of CPU registers are limited and they may busy doing some other task.
For example: if the microprocessor has 16-bit registers then they cannot hold a float value or a double value, which require 4 and 8 bytes respectively.
float (4 bytes)
=> 4 x 8
=> 32 bits
double (8 bytes)
=> 8 x 8
=> 64 bits
Output:
1 2 3 4 5 6 7 8 9 10
Leave a Comment