SlideShare a Scribd company logo
1 of 18
BESU, SUMMER-07
Topics
 Automatic variables
 External variables
 Static variables
 Register variables
 Scopes and longevity of above types of
variables.
1
BESU, SUMMER-07
1. Scope: the scope of a variable determines over what
part(s) of the program a variable is actually available
for use(active).
2. Longevity: it refers to the period during which a
variables retains a given value during execution of a
program(alive)
3. Local(internal) variables: are those which are declared
within a particular function.
4. Global(external) variables: are those which are
declared outside any function.
2
BESU, SUMMER-07
 Are declare inside a function in which they are to be
utilized.
 Are declared using a keyword auto.
eg. auto int number;
 Are created when the function is called and destroyed
automatically when the function is exited.
 This variable are therefore private(local) to the function
in which they are declared.
 Variables declared inside a function without storage
class specification is, by default, an automatic variable.
3
BESU, SUMMER-07
int main()
{ int m=1000;
function2();
printf(“%dn”,m);
}
function1()
{
int m = 10;
printf(“%dn”,m);
}
function2()
{ int m = 100;
function1();
printf(“%dn”,m);
}
4
Output
10
100
1000
BESU, SUMMER-07
 Any variable local to main will normally live throughout
the whole program, although it is active only in main.
 During recursion, the nested variables are unique auto
variables.
 Automatic variables can also be defined within blocks. In
that case they are meaningful only inside the blocks
where they are declared.
 If automatic variables are not initialized they will contain
garbage.
5
BESU, SUMMER-07
 These variables are declared outside any function.
 These variables are active and alive throughout the entire program.
 Also known as global variables and default value is zero.
 Unlike local variables they are accessed by any function in the
program.
 In case local variable and global variable have the same name, the
local variable will have precedence over the global one.
 Sometimes the keyword extern used to declare these variable.
 It is visible only from the point of declaration to the end of the program.
6
BESU, SUMMER-07
int number;
float length=7.5;
main()
{ . . .
. . .
}
funtion1()
{. . .
. . .
}
funtion1()
{. . .
. . .
}
7
int count;
main()
{count=10;
. . .
. . .
}
funtion()
{int count=0;
. . .
. . .
count=count+1;
}
The variable number and length
are available for use in all three
function
When the function references the
variable count, it will be referencing
only its local variable, not the global
one.
BESU, SUMMER-07
int x;
int main()
{
x=10;
printf(“x=%dn”,x);
printf(“x=%dn”,fun1());
printf(“x=%dn”,fun2());
printf(“x=%dn”,fun3());
}
int fun1()
{ x=x+10;
return(x);
}
int fun2()
{ int x
x=1;
return(x);
}
8
int fun3()
{
x=x+10;
return(x);
}
Once a variable has been declared
global any function can use it and
change its value. The subsequent
functions can then reference only that
new value.
Output
x=10
x=20
x=1
x=30
BESU, SUMMER-07
int
main()
{
y=5;
. . .
. . .
}
int y;
func1()
{
y=y+1
}
9
• As far as main is concerned, y is not
defined. So compiler will issue an error
message.
• There are two way out at this point
1. Define y before main.
2. Declare y with the storage class extern
in main before using it.
BESU, SUMMER-07
int main()
{
extern int y;
. . .
. . .
}
func1()
{
extern int y;
. . .
. . .
}
int y;
10
Note that extern declaration
does not allocate storage
space for variables
BESU, SUMMER-07
int main()
{
extern int m;
int i
. . .
. . .
}
function1()
{
int j;
. . .
. . .
}
11
file1.c
int m;
function2()
{
int i
. . .
. . .
}
function3()
{
int count;
. . .
. . .
}
file2.c
BESU, SUMMER-07
int m;
int main()
{
int i;
. . .
. . .
}
function1()
{
int j;
. . .
. . .
}
12
file1.c
extern int m;
function2()
{
int i
. . .
. . .
}
function3()
{
int count;
. . .
. . .
}
file2.c
BESU, SUMMER-07
 The value of static variables persists until the end of the
program.
 It is declared using the keyword static like
static int x;
static float y;
 It may be of external or internal type depending on the
place of there declaration.
 Static variables are initialized only once, when the
program is compiled.
13
BESU, SUMMER-07
 Are those which are declared inside a function.
 Scope of Internal static variables extend upto the end of
the program in which they are defined.
 Internal static variables are almost same as auto
variable except they remain in existence (alive)
throughout the remainder of the program.
 Internal static variables can be used to retain values
between function calls.
14
BESU, SUMMER-07
 Internal static variable can be used to count the number of calls
made to function. eg.
int main()
{
int I;
for(i =1; i<=3; i++)
stat();
}
void stat()
{
static int x=0;
x = x+1;
printf(“x = %dn”,x);
}
15
Output
x=1
x=2
x=3
BESU, SUMMER-07
 An external static variable is declared outside of all
functions and is available to all the functions in the
program.
 An external static variable seems similar simple external
variable but their difference is that static external
variable is available only within the file where it is defined
while simple external variable can be accessed by other
files.
16
BESU, SUMMER-07
 Static declaration can also be used to control the scope of a
function.
 If you want a particular function to be accessible only to the
functions in the file in which it is defined and not to any
function in other files, declare the function to be static. eg.
static int power(int x inty)
{
. . .
. . .
}
17
BESU, SUMMER-07
 These variables are stored in one of the machine’s register and are
declared using register keyword.
eg. register int count;
 Since register access are much faster than a memory access
keeping frequently accessed variables in the register lead to faster
execution of program.
 Since only few variable can be placed in the register, it is important
to carefully select the variables for this purpose. However, C will
automatically convert register variables into nonregister variables
once the limit is reached.
 Don’t try to declare a global variable as register. Because the
register will be occupied during the lifetime of the program.
18

More Related Content

What's hot (20)

Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Pointers
PointersPointers
Pointers
 
User defined functions
User defined functionsUser defined functions
User defined functions
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Functions in c
Functions in cFunctions in c
Functions in c
 
user defined function
user defined functionuser defined function
user defined function
 
Data Structure with C
Data Structure with CData Structure with C
Data Structure with C
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
Pointers and call by value, reference, address in C
Pointers and call by value, reference, address in CPointers and call by value, reference, address in C
Pointers and call by value, reference, address in C
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
Pointers
PointersPointers
Pointers
 
Pointers in C/C++ Programming
Pointers in C/C++ ProgrammingPointers in C/C++ Programming
Pointers in C/C++ Programming
 
11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
C functions list
C functions listC functions list
C functions list
 

Viewers also liked

10 річок світу
10 річок світу10 річок світу
10 річок світуlesyazagday
 
Presentacion Alonso
Presentacion AlonsoPresentacion Alonso
Presentacion Alonsomonedas
 
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016acocon GmbH
 
13 Konsep Beyond Leadership
13 Konsep Beyond Leadership13 Konsep Beyond Leadership
13 Konsep Beyond LeadershipUlfa Dwiyanti
 
Volshebnik izumrudnogo goroda
Volshebnik izumrudnogo gorodaVolshebnik izumrudnogo goroda
Volshebnik izumrudnogo gorodaDimon4
 
Presentacion Madrid
Presentacion MadridPresentacion Madrid
Presentacion Madridmonedas
 
Dot(Goodone)
Dot(Goodone)Dot(Goodone)
Dot(Goodone)ALI_Rehan
 
สมัครงาน
สมัครงานสมัครงาน
สมัครงานfindgooodjob
 
AASP.novembro.15.processoetico
AASP.novembro.15.processoeticoAASP.novembro.15.processoetico
AASP.novembro.15.processoeticoOsvaldo Simonelli
 
Caso de AESP
Caso de AESPCaso de AESP
Caso de AESPVarinska
 

Viewers also liked (19)

prueba
pruebaprueba
prueba
 
10 річок світу
10 річок світу10 річок світу
10 річок світу
 
Presentacion Alonso
Presentacion AlonsoPresentacion Alonso
Presentacion Alonso
 
Star craft 2
Star craft 2Star craft 2
Star craft 2
 
Geo 4-17-08 Notes
Geo 4-17-08 NotesGeo 4-17-08 Notes
Geo 4-17-08 Notes
 
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016
Splunk: Mehr Intelligenz für Ihren IT Service - Kinoforum 2016
 
13 Konsep Beyond Leadership
13 Konsep Beyond Leadership13 Konsep Beyond Leadership
13 Konsep Beyond Leadership
 
Volshebnik izumrudnogo goroda
Volshebnik izumrudnogo gorodaVolshebnik izumrudnogo goroda
Volshebnik izumrudnogo goroda
 
Expo
ExpoExpo
Expo
 
Presentacion Madrid
Presentacion MadridPresentacion Madrid
Presentacion Madrid
 
Dot(Goodone)
Dot(Goodone)Dot(Goodone)
Dot(Goodone)
 
DSRao
DSRaoDSRao
DSRao
 
สมัครงาน
สมัครงานสมัครงาน
สมัครงาน
 
AASP.novembro.15.processoetico
AASP.novembro.15.processoeticoAASP.novembro.15.processoetico
AASP.novembro.15.processoetico
 
L9 gastric carcinoma f
L9 gastric carcinoma fL9 gastric carcinoma f
L9 gastric carcinoma f
 
El cancer
El cancerEl cancer
El cancer
 
Caso de AESP
Caso de AESPCaso de AESP
Caso de AESP
 
L19 hepatic failure
L19 hepatic failureL19 hepatic failure
L19 hepatic failure
 
Python Κεφ. 1.4 Δομή Επανάληψης
Python Κεφ. 1.4 Δομή ΕπανάληψηςPython Κεφ. 1.4 Δομή Επανάληψης
Python Κεφ. 1.4 Δομή Επανάληψης
 

Similar to storage clas

What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignmentAhmad Kamal
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programmingnmahi96
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
15 functions
15 functions15 functions
15 functionsfyjordan9
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoMark John Lado, MIT
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfBoomBoomers
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxSangeetaBorde3
 

Similar to storage clas (20)

What is storage class
What is storage classWhat is storage class
What is storage class
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
Function in C++
Function in C++Function in C++
Function in C++
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
5.program structure
5.program structure5.program structure
5.program structure
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
15 functions
15 functions15 functions
15 functions
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
USER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdfUSER DEFINED FUNCTIONS IN C.pdf
USER DEFINED FUNCTIONS IN C.pdf
 
Functions
FunctionsFunctions
Functions
 
Functions
FunctionsFunctions
Functions
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 

More from teach4uin

Master pages
Master pagesMaster pages
Master pagesteach4uin
 
.Net framework
.Net framework.Net framework
.Net frameworkteach4uin
 
Scripting languages
Scripting languagesScripting languages
Scripting languagesteach4uin
 
State management
State managementState management
State managementteach4uin
 
security configuration
security configurationsecurity configuration
security configurationteach4uin
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tagsteach4uin
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tagsteach4uin
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentationteach4uin
 
.Net overview
.Net overview.Net overview
.Net overviewteach4uin
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lessonteach4uin
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrolsteach4uin
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperatorteach4uin
 

More from teach4uin (20)

Controls
ControlsControls
Controls
 
validation
validationvalidation
validation
 
validation
validationvalidation
validation
 
Master pages
Master pagesMaster pages
Master pages
 
.Net framework
.Net framework.Net framework
.Net framework
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
Css1
Css1Css1
Css1
 
Code model
Code modelCode model
Code model
 
Asp db
Asp dbAsp db
Asp db
 
State management
State managementState management
State management
 
security configuration
security configurationsecurity configuration
security configuration
 
static dynamic html tags
 static dynamic html tags static dynamic html tags
static dynamic html tags
 
static dynamic html tags
static dynamic html tagsstatic dynamic html tags
static dynamic html tags
 
New microsoft office power point presentation
New microsoft office power point presentationNew microsoft office power point presentation
New microsoft office power point presentation
 
.Net overview
.Net overview.Net overview
.Net overview
 
Stdlib functions lesson
Stdlib functions lessonStdlib functions lesson
Stdlib functions lesson
 
enums
enumsenums
enums
 
array
arrayarray
array
 
Cprogrammingprogramcontrols
CprogrammingprogramcontrolsCprogrammingprogramcontrols
Cprogrammingprogramcontrols
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 

Recently uploaded

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 

Recently uploaded (20)

Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 

storage clas

  • 1. BESU, SUMMER-07 Topics  Automatic variables  External variables  Static variables  Register variables  Scopes and longevity of above types of variables. 1
  • 2. BESU, SUMMER-07 1. Scope: the scope of a variable determines over what part(s) of the program a variable is actually available for use(active). 2. Longevity: it refers to the period during which a variables retains a given value during execution of a program(alive) 3. Local(internal) variables: are those which are declared within a particular function. 4. Global(external) variables: are those which are declared outside any function. 2
  • 3. BESU, SUMMER-07  Are declare inside a function in which they are to be utilized.  Are declared using a keyword auto. eg. auto int number;  Are created when the function is called and destroyed automatically when the function is exited.  This variable are therefore private(local) to the function in which they are declared.  Variables declared inside a function without storage class specification is, by default, an automatic variable. 3
  • 4. BESU, SUMMER-07 int main() { int m=1000; function2(); printf(“%dn”,m); } function1() { int m = 10; printf(“%dn”,m); } function2() { int m = 100; function1(); printf(“%dn”,m); } 4 Output 10 100 1000
  • 5. BESU, SUMMER-07  Any variable local to main will normally live throughout the whole program, although it is active only in main.  During recursion, the nested variables are unique auto variables.  Automatic variables can also be defined within blocks. In that case they are meaningful only inside the blocks where they are declared.  If automatic variables are not initialized they will contain garbage. 5
  • 6. BESU, SUMMER-07  These variables are declared outside any function.  These variables are active and alive throughout the entire program.  Also known as global variables and default value is zero.  Unlike local variables they are accessed by any function in the program.  In case local variable and global variable have the same name, the local variable will have precedence over the global one.  Sometimes the keyword extern used to declare these variable.  It is visible only from the point of declaration to the end of the program. 6
  • 7. BESU, SUMMER-07 int number; float length=7.5; main() { . . . . . . } funtion1() {. . . . . . } funtion1() {. . . . . . } 7 int count; main() {count=10; . . . . . . } funtion() {int count=0; . . . . . . count=count+1; } The variable number and length are available for use in all three function When the function references the variable count, it will be referencing only its local variable, not the global one.
  • 8. BESU, SUMMER-07 int x; int main() { x=10; printf(“x=%dn”,x); printf(“x=%dn”,fun1()); printf(“x=%dn”,fun2()); printf(“x=%dn”,fun3()); } int fun1() { x=x+10; return(x); } int fun2() { int x x=1; return(x); } 8 int fun3() { x=x+10; return(x); } Once a variable has been declared global any function can use it and change its value. The subsequent functions can then reference only that new value. Output x=10 x=20 x=1 x=30
  • 9. BESU, SUMMER-07 int main() { y=5; . . . . . . } int y; func1() { y=y+1 } 9 • As far as main is concerned, y is not defined. So compiler will issue an error message. • There are two way out at this point 1. Define y before main. 2. Declare y with the storage class extern in main before using it.
  • 10. BESU, SUMMER-07 int main() { extern int y; . . . . . . } func1() { extern int y; . . . . . . } int y; 10 Note that extern declaration does not allocate storage space for variables
  • 11. BESU, SUMMER-07 int main() { extern int m; int i . . . . . . } function1() { int j; . . . . . . } 11 file1.c int m; function2() { int i . . . . . . } function3() { int count; . . . . . . } file2.c
  • 12. BESU, SUMMER-07 int m; int main() { int i; . . . . . . } function1() { int j; . . . . . . } 12 file1.c extern int m; function2() { int i . . . . . . } function3() { int count; . . . . . . } file2.c
  • 13. BESU, SUMMER-07  The value of static variables persists until the end of the program.  It is declared using the keyword static like static int x; static float y;  It may be of external or internal type depending on the place of there declaration.  Static variables are initialized only once, when the program is compiled. 13
  • 14. BESU, SUMMER-07  Are those which are declared inside a function.  Scope of Internal static variables extend upto the end of the program in which they are defined.  Internal static variables are almost same as auto variable except they remain in existence (alive) throughout the remainder of the program.  Internal static variables can be used to retain values between function calls. 14
  • 15. BESU, SUMMER-07  Internal static variable can be used to count the number of calls made to function. eg. int main() { int I; for(i =1; i<=3; i++) stat(); } void stat() { static int x=0; x = x+1; printf(“x = %dn”,x); } 15 Output x=1 x=2 x=3
  • 16. BESU, SUMMER-07  An external static variable is declared outside of all functions and is available to all the functions in the program.  An external static variable seems similar simple external variable but their difference is that static external variable is available only within the file where it is defined while simple external variable can be accessed by other files. 16
  • 17. BESU, SUMMER-07  Static declaration can also be used to control the scope of a function.  If you want a particular function to be accessible only to the functions in the file in which it is defined and not to any function in other files, declare the function to be static. eg. static int power(int x inty) { . . . . . . } 17
  • 18. BESU, SUMMER-07  These variables are stored in one of the machine’s register and are declared using register keyword. eg. register int count;  Since register access are much faster than a memory access keeping frequently accessed variables in the register lead to faster execution of program.  Since only few variable can be placed in the register, it is important to carefully select the variables for this purpose. However, C will automatically convert register variables into nonregister variables once the limit is reached.  Don’t try to declare a global variable as register. Because the register will be occupied during the lifetime of the program. 18