by Dinesh Thakur Category: Type And Variables

A storage class specifies how the variables are used in the program.

Static storage class or variable

A variable is declared to be static by prefixing its normal declaration with the keyword static, as in static int a;

Since the property of a variable may be stated in any order we could also use int static a; Static variables can be declared within a function. These variables retain their values from the previous call. i.e., the value that they had before returning from the function.

Register storage class

Register variables are stored in the register of the microprocessor. The number of variable which can be declared register are limited. This means that the variable has a maximum size equal to the register size. If more variables are declared as register variable, they are treated as auto variables. A program that uses register variables executes faster as compared to similar program without register variable.

Automatic storage class or variables

The scope of an automatic variable is only for the block, or any block within the block, in which it appears. All variables declared within a function are auto by default. A variable can be defined as automatic by placing the keyword auto at the beginning of the variable declaration.

Example: auto int a;

External Storage class or Global variable

External variables are global to the file in which they are defined. External variables are used only when all functions needed a particular variable. It retains the assigned value within the scope. In the following program variable i is an external variable.

Example: extern int a;

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content