storage classes, storage classes in C++, storage classes program example
What are storage classes? Explain different types of storage classes. 

A storage class refers to the scope of data in a program. Scope of data means the portion of the program in which the variable is valid( main() as well as sub programs) and lifetime of the variable.i.e., the length of time to which the variable retains its value.
A variable must belong to any one of the following storage classes.
1. Automatic storage class
2. External storage class
3. Register storage class
4. Static storage class

Automatic storage class:
Automatic storage class is similar to local variable declaration. Keyword auto precedes the declaration.

Example:
auto int x,y,z;
1. Automatic variables are local variables.
2. The variables are stored in memory(RAM).
3. The key word auto is implicit(it means even without the word auto the variable is automatic).
4. Initial value stored is junk.

External storage class:
External storage class is similar to global variables. Keyword extern precedes the declaration
Example:
extern int m,n;
1. Scope of the variable is global.
2. The variables are stored in memory.
3. Needs explicit(must use the keyword) declaration.
4. Initial value stored is junk.

Register storage class:
Register storage class is used when data is needed in CPU registers. Keyword register must precede the declaration
Example:
register int x,y;
1. Scope of the variable is local
2. The variables are stored in registers.
3. Needs explicit declaration.
4. Initial value is not known.

Static storage class:
Static storage class is used in function blocks. The static variable can be initialized exactly once when the function is called for the first time. For subsequent calls to the same
function, the static variable stores the most recent value. Keyword static precedes the variable declaration.
Example: 
static int x,y,z;
1. Scope of the variable is local
2. The variables are stored in memory
3. Needs explicit declaration
4. Default Initial value is stored is 0.



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: