STORAGE CLASS

Every variable in C program has two properties: type and storage class. Type refers to the data type of variable And storage class determines how long it stays in existence i.e Storage duration – how long an object (a program element) can exists in memory And the Scope – where object (a program element) can be referenced in program. C Support Four types of Storage classes:
1. Automatic OR Local
2. Register
3. Static
4. Extern OR Global

AUTOMATIC VARIABLE

1. The keyword auto is used to declare or define an automatic variables Ex: auto double x, y;
2. The default scope of variables declared or defined within a block is Local / Automatic.
3. These program elements are created and destroyed within its block.
4. NO Default value exist for a Local variable i.e it possess a JUNK value when uninitialized.

Program to illustrate Automatic Variables.

#include<stdio.h>
int main()
{ int x = 9, y = 8, z = 5, t;
printf(“\nX=%d Y=%d Z=%d T=%d”, x, y, z, t);
if(x == 9)
{
int z = 25, a= 55;
printf(“\nX=%d Y=%d Z=%d a = %d”, x, y, z, a);
}
printf(“\nX=%d Y=%d Z=%d”, x, y, z);
getch(); return 0;
}

STORAGE CLASS STORAGE CLASS Reviewed by Unknown on 04:45 Rating: 5

No comments:

Powered by Blogger.