Storage Classes in the C++ language.

C++ Programming Tutorial

Storage Classes in the C++ language.


This is a concept derived from the "C" language, in which it is decided which data is being stored and how it is being used. By using the Concept of Storage class.






Declarations and Definitions of Storage Classes.

When we give a name to a Variable or Function and decide its Data Type, this process is called Declaration. The declaration is information for Compiler. The compiler does not take any action on a Declaration.

To allocate space in memory for the Compiler Variable. We have tried to note the difference between these two at many places while explaining the functions.

void function(); // function declaration void function() // function definition { // statements }

Automatic Variables.

Variables that are declared within a block are useable, they are Automatic Variables.

void func() { int ivar; // automatic variables float fvar; }

Register Variables

Register Variable is a special type of Automatic Variable. When we want to declare a register class to a Variable, then we have to use register Keyword. That is, we can declare a Variable of Register Class.

register int Total;

External Variables

Variables that are declared outside a function or class are called Variables of External Storage Class. These are also called Global Variables.

Local Static Variables

A variable that is declared with static keyword is called static variable.

void function1() { int x=10;//local variable static int y=10;//static variable x=x+1; y=y+1; printf("%d,%d",x,y); }

If you call this function many times, local variable will print the same value for each function call e.g, 11,11,11 and so on. But static variable will print the incremented value in each function call e.g. 11, 12, 13 and so on.

C++ Storage Classes
Storage Classes