Storage class
in C
Storage class defines the
scope (visibility) and lifetime of variables and/or functions declared within a
C program. It stored in RAM or CPU
register. There are Four storage class into which variables are declared &
stored.
1. Auto storage class.
2. Static storage class.
3. Extern storage class.
4. Register storage class.
1. Auto storage class: - Variable declared in this class is
stored In RAM. This is the default storage class and the keyword ‘auto’ is used
declare variables. Auto variables are active in a block in which they are
declare. Auto storage class is commonly used in all C program without a keyword
‘auto’.
Example:- auto int a;
2. Static storage class:- Variables declares in this class are also stored in
the RAM. The keyword ‘static’ is used to declare these variables. Similar to
auto variable, the static variable are also active in the block which they are
declared and they retain the latest value.
Example: static int a=10;
3. Extern storage class: - Global variable are decided using
this class & they are stored in RAM. The key ‘extern’ is used to declare
this variable. The global variables are also declared outside the main
function. Extern class can be used consider a local variable in a block as a
global variable.
Example: - extern int a;
4. Register storage class: - Variables declare using this class is
stored in the CPU memory register. The keyword register is used to declare
these variables. Only a few variables which are frequently used in the program
and declared using this class to improve the program executing speed. The behaviour
of register variable is similar to that of auto variables except that their
storage locations are different. In case of non availability of CPU memory
register, these variables are stored in RAM as auto variables.
Example: - register int a;
Comments
Post a Comment
please subscribe my blog and let me suggest how I improve this site