Types of Variables and Storage Classes

In a program consisting of a number of functions, a number of different types of variables can be found.

Global vs. Static variables

Global variables are recognized throughout the program whereas local valuables are recognized only within the function where they are defined.

Static vs. Dynamic variables

Retention of value by a local variable means, that in static, retention of the variable value is lost once the function is completely executed whereas in certain conditions the value of the variable has to be retained from the earlier execution and the execution retained.

The variables can be characterized by their data type and by their storage class. One way to classify a variable is according to its data type and the other can be through its storage class. Data type refers to the type of value represented by a variable whereas storage class refers to the permanence of a variable and its scope within the program i.e. portion of the program over which variable is recognized.

Storage Classes

There are four different storage classes specified in C:

1. Auto (matic)
2. Extern (al)
3. Static
4. Register

The storage class associated with a variable can sometimes be established by the location of the variable declaration within the program or by prefixing keywords to variables declarations.

For example:

auto int a, b;
static int a, b;
extern float f;

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: