/
Storage Class Storage Class

Storage Class - PowerPoint Presentation

mitsue-stanley
mitsue-stanley . @mitsue-stanley
Follow
385 views
Uploaded On 2016-12-23

Storage Class - PPT Presentation

Specifiers AUTO Key word auto precedes the normal variable declaration All local variables are auto by default Created when function is called and destroyed when function terminates Life time of function run time ID: 505332

variable function file variables function variable variables file auto local static files extern program time created declared scope cout

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Storage Class" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Storage Class SpecifiersSlide2

AUTO

Key word auto precedes the normal variable declaration

All local variables are auto by default

Created when function is called and destroyed when function terminates

Life time of function run time

Local auto variables have function scope

Can be applied only to local variablesSlide3

REGISTER

Keyword register is used

It is an auto declaration

Has all features of an auto variable

Provide faster access compared to other variables since they are stored in CPU registers

*

rather than memory

Can be applied only to local variables

*

a processor register is a small amount of storage available as part of a CPU or other digital processor.Slide4

STATIC

1) static global variable

* variable is globally available for the file in which it appears

Cannot be accessed from other files

2) Static Local variable

Created when the function is called

Not destroyed when the function is terminated.

Rather, value is retained in memory.

But, can be accessed only inside the function

Hence, it has function scope and program run life timeSlide5

EXTERN

Used when a program is spread across files

A

global variable

can be created with keyword

extern

(extern variable cannot be created locally)

Can be accessed across files.

Tells the compiler that variables and names declared as extern have been declared else where and fresh memory need not be allocated to these variables

Has file scope and program runtime.Slide6

Storage class specifiers

for Functions

By

default

, C++ functions have

program life time

and can be shared

across files

.

If declared static, the function has file scope.

Ie

, can be used only inside the file in which it appears and another file can use the same name for a

different function.

If declared extern, it means that the function has been defined in another file.

Useful for programs spread across files.Slide7

#include<

iostream.h

>

#include<

conio.h

>

void print()

{

static

int

x=1;

int

i

;

for(

i

=0;i<10;i++)

x++;

cout

<<"\n\n x= "<<x;

}

void main()

{

clrscr

();

cout

<<"First call...";

print();

cout

<<"\n\

nSecond

call..";

print();

getch

();

}

Out put:-

First Call…

11

Second call….

21