Data type that define whether it is capable of storing integer value or character value or fractional value (float).
Storage type defines the existence of variable in the memory as well as its visibility in the program.
On the basis we can categorize storage class as :
auto
register
extern
static
AUTOMATIC VARIABLES :
The variable that is defined inside a function is known as an automatic variable.
We may or may not use the auto keyword before the datatype.Because compiler will automatically assume it to be auto.
The scope is only inside the function in which it is declared.
This is the default storage class for all the variables declared inside a function or a block.
Hence, the keyword auto is rarely used while writing programs in C language.
Auto variables can be only accessed within the block/function they have been declared and not outside them.
They are assigned with a garbage value by default whenever they are declared.
SCOPE :
Local to Block where it is defined.
INITIAL VALUE :
GARBAGE VALUE.
LIFETIME :
Till the end of a function.
EXTENDED VARIABLES :
Variable of this storage class are global variables.
Extern storage class will have global scope and hence will be available to all the functions.
Extern variable will exist as long as program execution continues.
SCOPE :
AVAILABLE EVERYWHERE.
INITIAL VALUE :
ZERO.
LIFETIME :
Till the program did not finish execution.
STATIC VARIABLES :
When a variable within a function is declared with the static, it instructs the compiler to keep a local variable in existence permanently.
It means that the variable has a permanent duration during the lifetime of program.
In other words, the memory storage allocated for the variable is not destroyed when the scope of the variable is exited.
SCOPE :
Local to Block where it is defined.
INITIAL VALUE :
ZERO.
LIFETIME :
Till the program did not finish execution.
REGISTER :
Local variables are stored in register instead of RAM.
Computer has a certain number of registers to hold data and perform arithmetic or logical calculations.
Because registers are located within the CPU (Central Processing Unit) chip, it’s much quicker to access a register than a memory location which resides outside the chip.
Therefore, storing variables in register might help to speed up your program.
Comments
Post a Comment