SlideShare a Scribd company logo
Storage class in C
INTRODUCTION
• Not only variables have data types but also a storage class..
• Where the variable would be stored.
• Default initial value if not specifically assigned.
• Scope i.e in which function the value would be available.
• How log would the variable exist.
CLASSIFICATION
• Automatic storage class
• Register storage class
• Static storage class
• External storage class
AUTOMATIC STORAGE CLASS
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.
EXAMPLE PROGRAM
int main()
{ int m=1000;
function2();
printf(“%d n”,m);
}
function1()
{
int m = 10;
printf(“%dn”,m);
}
function2()
{ int m = 100;
function1();
printf(“%dn”,m);
}
Output
10
100
1000
EXTERNAL STORAGE CLASS
• 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.
EXTERNAL VARIABLE (EXAMPLES)
int n;
main()
{ increment();
increment();
decrement();
}
increment()
{n=n+1;
Printf(“ inc value %d”,n);
}
decrement()
{n=n-1
Printf(“ inc value %d”,n);
}
int x=10;
main()
{int x=20;
printf(“n %d”,x);
display();
}
display()
{
printf(“n %d”,x);
}
The variable n is 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.
STATIC STORAGE CLASS
• 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.
EXAMPLE OF STATIC
• 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);
}
Output
x=1
x=2
x=3
REGISTER STORAGE CLASS
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.
Storage class in c

More Related Content

What's hot

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
Syed Mustafa
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
Self employed
 
Enums in c
Enums in cEnums in c
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
Nitesh Kumar Pandey
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Nilesh Dalvi
 
STORAGE CLASSES
STORAGE CLASSESSTORAGE CLASSES
STORAGE CLASSES
sathish sak
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
Nikhil Pandit
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 

What's hot (20)

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
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Enums in c
Enums in cEnums in c
Enums in c
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
File in C language
File in C languageFile in C language
File in C language
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
STORAGE CLASSES
STORAGE CLASSESSTORAGE CLASSES
STORAGE CLASSES
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Function in C program
Function in C programFunction in C program
Function in C program
 

Viewers also liked

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
Jake Bond
 
C and its errors
C and its errorsC and its errors
C and its errors
Junaid Raja
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
Reddhi Basu
 
Design Pattern Libraries
Design Pattern LibrariesDesign Pattern Libraries
Design Pattern Libraries
Brian Peppler
 
Loops in C
Loops in CLoops in C
Loops in C
Kamal Acharya
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Arrays
ArraysArrays
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 

Viewers also liked (10)

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
C and its errors
C and its errorsC and its errors
C and its errors
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Design Pattern Libraries
Design Pattern LibrariesDesign Pattern Libraries
Design Pattern Libraries
 
Loops in C
Loops in CLoops in C
Loops in C
 
Loops c++
Loops c++Loops c++
Loops c++
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 

Similar to Storage class in c

S torage class in C
S torage class in CS torage class in C
S torage class in C
kash95
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
Jenish Bhavsar
 
C functions list
C functions listC functions list
Functions in c
Functions in cFunctions in c
Functions in c
SunithaVesalpu
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
What is storage class
What is storage classWhat is storage class
What is storage class
Isha Aggarwal
 
Storage class
Storage classStorage class
Storage class
Kalaikumar Thangapandi
 
Storage class
Storage classStorage class
Storage class
Kathmandu University
 
function in c
function in cfunction in c
function in c
subam3
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Storage classes
Storage classesStorage classes
Storage classes
Puneet Rajput
 
Lecture6
Lecture6Lecture6
Unit iii
Unit iiiUnit iii
Unit iii
SHIKHA GAUTAM
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Storage class
Storage classStorage class
Storage class
MANJULA_AP
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
Durgadevi palani
 
5.program structure
5.program structure5.program structure
5.program structure
Shankar Gangaju
 
Unit 8
Unit 8Unit 8
Unit 8
rohassanie
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
sameermhr345
 
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
웅식 전
 

Similar to Storage class in c (20)

S torage class in C
S torage class in CS torage class in C
S torage class in C
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
C functions list
C functions listC functions list
C functions list
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Storage class
Storage classStorage class
Storage class
 
Storage class
Storage classStorage class
Storage class
 
function in c
function in cfunction in c
function in c
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Storage classes
Storage classesStorage classes
Storage classes
 
Lecture6
Lecture6Lecture6
Lecture6
 
Unit iii
Unit iiiUnit iii
Unit iii
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Storage class
Storage classStorage class
Storage class
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
5.program structure
5.program structure5.program structure
5.program structure
 
Unit 8
Unit 8Unit 8
Unit 8
 
Funtions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the topsFuntions of c programming. the functions of c helps to clarify all the tops
Funtions of c programming. the functions of c helps to clarify all the tops
 
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
 

Recently uploaded

[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...
IJECEIAES
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 

Recently uploaded (20)

[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...Adaptive synchronous sliding control for a robot manipulator based on neural ...
Adaptive synchronous sliding control for a robot manipulator based on neural ...
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 

Storage class in c

  • 2. INTRODUCTION • Not only variables have data types but also a storage class.. • Where the variable would be stored. • Default initial value if not specifically assigned. • Scope i.e in which function the value would be available. • How log would the variable exist.
  • 3. CLASSIFICATION • Automatic storage class • Register storage class • Static storage class • External storage class
  • 4. AUTOMATIC STORAGE CLASS 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.
  • 5. EXAMPLE PROGRAM int main() { int m=1000; function2(); printf(“%d n”,m); } function1() { int m = 10; printf(“%dn”,m); } function2() { int m = 100; function1(); printf(“%dn”,m); } Output 10 100 1000
  • 6. EXTERNAL STORAGE CLASS • 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.
  • 7. EXTERNAL VARIABLE (EXAMPLES) int n; main() { increment(); increment(); decrement(); } increment() {n=n+1; Printf(“ inc value %d”,n); } decrement() {n=n-1 Printf(“ inc value %d”,n); } int x=10; main() {int x=20; printf(“n %d”,x); display(); } display() { printf(“n %d”,x); } The variable n is 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. STATIC STORAGE CLASS • 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.
  • 9. EXAMPLE OF STATIC • 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); } Output x=1 x=2 x=3
  • 10. REGISTER STORAGE CLASS 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.