ASSINMENT IN C OF 'O' LEVEL

Search This Blog

Wednesday, 13 July 2011

STORAGE CLASS

A storage class defines the scope & life time of variables &/or functions within a c program.

There are four storage classes in c.

  • Automatic storage class(keyword-auto)
  • Register storage class(keyword-register)
  • Static storage class(keyword- static)
  • External storage class(keyword-extern)

    Note:-

    (1-)
    Automatic, Static, External storage classes are having same

    Storage- Memory while Register storage class has storage-CPU Register.

    (2-)Automatic & Register storage classes are having same

    Default initial value-Garbage value whereas Static & External storage class are having same Default initial value- zero.

    (3-)
    Automatic, Register & Static storage classes are having same

    Scope-Local to the block in which the variable is defined while External storage class has Scope- Global.

    (4-) Automatic & Register storage class are having same Life- Till the control remains within the block in which the variable is defined whereas Static storage class has Life-Value of the variable persists between different function calls
    & External storage class has Life-AS long as the program's execution doesn't come to an end.


     

Features of a variable

Automatic storage class

Register storage class

Static storage class

External storage class

Storage

memory

CPU Register

memory

memory

Default initial value

Garbage value

Garbage value

zero

zero

Scope

Local to the block in which the variable is defined

Local to the block in which the variable is defined

Local to the block in which the variable is defined

Global

Life

Till the control remains within the block in which the variable is defined

Till the control remains within the block in which the variable is defined

Value of the variable persists between different function calls

As long as the program's execution doesn't come to an end

Keywords

auto

register

static

extern