0% found this document useful (0 votes)
82 views10 pages

Storage Class

There are two kinds of storage locations for variables: memory and CPU registers. A variable's storage class determines its storage location, initial value, scope, and lifetime. The four storage classes are auto, register, static, and external. Auto variables are stored in memory with a garbage initial value and local scope that lasts until the block ends. Register variables are similar but stored in CPU registers for faster access. Static variables persist between function calls and are stored in memory with an initial value of zero and local block scope. External variables are global in scope and persist for the program's lifetime, stored in memory with an initial value of zero.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views10 pages

Storage Class

There are two kinds of storage locations for variables: memory and CPU registers. A variable's storage class determines its storage location, initial value, scope, and lifetime. The four storage classes are auto, register, static, and external. Auto variables are stored in memory with a garbage initial value and local scope that lasts until the block ends. Register variables are similar but stored in CPU registers for faster access. Static variables persist between function calls and are stored in memory with an initial value of zero and local block scope. External variables are global in scope and persist for the program's lifetime, stored in memory with an initial value of zero.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Storage Classes

Two kinds of storage locations. Memory and CPU registers.

Variables storage class tells


Storage location Initial value Scope of the variable Life of the variable

Four storage classes


auto register static external

auto
Storage Location - Memory

Initial Value Scope


Life

- Garbage Value - Local to the block in which the variable is defined. - Till the control remains within the block in which the variable is defined.

Implicitly all the variables are auto storage class.

Example: auto int a,b; #include<stdio.h> #include<conio.h> main() { auto int a; clrscr(); printf (%d,a); getch() }

register
Storage Location CPU register Initial Value Scope Life - Garbage Value - Local to the block in which the variable is defined. - Till the control remains within the block in which the variable is defined.

A value stored in a CPU register can be accessed faster than the one which is stored in memory.

Example: register int a,b; #include<stdio.h> #include<conio.h> main() { register int a; clrscr(); printf(%d,a); getch() }

static
Storage Location - Memory Initial Value - Zero Scope - Local to the block in which the variable is defined. Life - value of the variable persists b/w different function calls.

Static variables are maintaining value between different function calls.

Example: static int a,b; #include<stdio.h> #include<conio.h> main() { increase(); increase(); increase(); } increase() { static int a=1; printf(%d,a); a=a+1; getch(); }

external
Storage Location Initial Value Scope Life - Memory - Zero - Global - As long as the programs execution doesnt come to an end.

Example: external int a,b; #include<stdio.h> #include<conio.h> external int a; main() { clrscr(); printf(%d,a); getch() }

You might also like