SlideShare a Scribd company logo
BY,
A.Amalajoylet
Storage classes
STORAGE CLASSES
 The storage class determines the part of the
memory where the variables would be stored.
 The storage class also determines the initial
value of the variable.
 It is used to define the scope and lifetime of
variable.
 There are two storage locations in computer,
 1. CPU Registers
 2.Memory.
 A value stored in CPU register can always be
accessed faster than the one that is stored in
memory.
Four types
1.Automatic storage class.
2.Register storage class.
3.Static storage class.
4.External storage class.
Automatic
 Keywords : Auto
 Storage : Memory
 Default initial value : Garbage value
 Scope : Local/Block scope
 Life : Exists as long as
the control
remains in the
block
Example for Automatic
 void main()
{
auto x= 20 ;
{
auto x = 60 ;
printf("n x: %d",x);
}
printf("nx: %d",x);
}
 OUTPUT :
 x: 60
x: 20
 NOTE : Two variables are declared in different
blocks , so they are treated as different variables
Static
 Keywords : Static
 Storage : Memory
 Default initial value : 0
 Scope : Local to the block in
which
the variable is
defined.
 Life : Value of the variable
persists
between different
function calls.
Difference between auto and static
class
 /*auto class*/
#include<stdio.h>
void add();
int main()
{
add();
add();
add();
add();
return 0;
}
void add()
{
auto int i=1;
printf("n%d",i);
i=i+1;
 OUTPUT:-
1
1
1
1
 /*static class*/
#include<stdio.h>
void add();
int main()
{
add();
add();
add();
add();
return 0;
}
void add()
{
static int i=1;
printf("n%d",i);
i=i+1;
}
 OUTPUT:-
1
2
3
4

Previous program explanation
 If the storage class is static, then the statement
static int i = 1 is executed only once, irrespective
of how many times the same function is called.
 If the storage class is auto,then the statement
auto int i=1 is executed each time where it
increments and re-initialize the value of i= 1.
 The difference between them is
that static variable do not disappear when the
function is no longer active. There value persist. If
control comes back to the same function again ,
the static variables have the same values they
had last time around.
Register
 Keywords : Register.
 Storage : CPU register.
 Default initial value : Garbage value
 Scope : Local to the block in
which
the variable is
defined.
 Life : Value of the variable
persists
till the control
remains within
the block in which
Why we need Register Variable
?
 Whenever we declare any variable inside C Program
then memory will be randomly allocated at particular
memory location.
 We have to keep track of that memory location. We
need to access value at that memory location using
ampersand operator/Address Operator i.e (&).
 If we store same variable in the register memory then
we can access that memory location directly without
using the Address operator.
 Register variable will be accessed faster than the
normal variable thus increasing the operation and
program execution. Generally we use register variable
as Counter.
 Note : It is not applicable for arrays, structures or
pointers.
External
 Keywords : Extern.
 Storage : Memory.
 Default initial value : 0
 Scope : Global
 Life : Exists as long as
variable is
running
Retains value within
the function
Example for Extern
 int num = 75 ;
void display();
void main()
{
extern int num ;
printf("nNum : %d",num);
display();
}
void display()
{
extern int num ;
printf("nNum : %d",num);
}
 OUTPUT:
 Num : 75
Num : 75
Extern contd…
Note :Declaration within the function indicates
that the function uses external variable
Functions belonging to same source code ,
does not require declaration (no need to write
extern)
If variable is defined outside the source code ,
then declaration using extern keyword is
required
 THANK YOU

More Related Content

PPTX
Storage classes in C
Nitesh Bichwani
 
PPTX
Storage class in c
kash95
 
PPTX
Union in C programming
Kamal Acharya
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPSX
Modules and packages in python
TMARAGATHAM
 
PPT
structure and union
student
 
PPTX
This pointer
Kamal Acharya
 
PPTX
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Storage classes in C
Nitesh Bichwani
 
Storage class in c
kash95
 
Union in C programming
Kamal Acharya
 
Data Types & Variables in JAVA
Ankita Totala
 
Modules and packages in python
TMARAGATHAM
 
structure and union
student
 
This pointer
Kamal Acharya
 
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 

What's hot (20)

PPTX
Array Of Pointers
Sharad Dubey
 
PPTX
Structures in c language
tanmaymodi4
 
PPTX
Constructor and Types of Constructors
Dhrumil Panchal
 
PPTX
Storage class in C Language
Nitesh Kumar Pandey
 
PPTX
Functions in python
colorsof
 
PPT
friend function(c++)
Ritika Sharma
 
PPTX
Java Method, Static Block
Infoviaan Technologies
 
PPTX
Programming in c Arrays
janani thirupathi
 
PPT
Operators in C Programming
programming9
 
PPT
File handling in c
David Livingston J
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
ODP
Python Modules
Nitin Reddy Katkam
 
PPT
Strings
Mitali Chugh
 
PPTX
Call by value or call by reference in C++
Sachin Yadav
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Call by value
Dharani G
 
PPTX
Union in c language
tanmaymodi4
 
PPTX
Python Functions
Mohammed Sikander
 
PPTX
Data types in c++
Venkata.Manish Reddy
 
PPTX
C Programming: Control Structure
Sokngim Sa
 
Array Of Pointers
Sharad Dubey
 
Structures in c language
tanmaymodi4
 
Constructor and Types of Constructors
Dhrumil Panchal
 
Storage class in C Language
Nitesh Kumar Pandey
 
Functions in python
colorsof
 
friend function(c++)
Ritika Sharma
 
Java Method, Static Block
Infoviaan Technologies
 
Programming in c Arrays
janani thirupathi
 
Operators in C Programming
programming9
 
File handling in c
David Livingston J
 
Function in C program
Nurul Zakiah Zamri Tan
 
Python Modules
Nitin Reddy Katkam
 
Strings
Mitali Chugh
 
Call by value or call by reference in C++
Sachin Yadav
 
Functions in c language
tanmaymodi4
 
Call by value
Dharani G
 
Union in c language
tanmaymodi4
 
Python Functions
Mohammed Sikander
 
Data types in c++
Venkata.Manish Reddy
 
C Programming: Control Structure
Sokngim Sa
 
Ad

Similar to Storage class (20)

DOCX
Storage class
Kalaikumar Thangapandi
 
PPT
Storage classes
Leela Koneru
 
PPT
Storage classes
Leela Koneru
 
PPTX
Storage classes in c language
tanmaymodi4
 
PPTX
Storage classes in c language
Tanmay Modi
 
PPTX
Storage classes
UTTAM VERMA
 
PPT
STORAGE CLASSES
sathish sak
 
PPTX
Storage Class Specifiers in C++
Reddhi Basu
 
PPT
Storage classes
Praveen M Jigajinni
 
PPTX
Storage classes
priyanka jain
 
DOC
What is storage class
Isha Aggarwal
 
PDF
Latest C Interview Questions and Answers
DaisyWatson5
 
PPTX
Storage classes
Puneet Rajput
 
PPTX
Storage Class in C Progrmming
Kamal Acharya
 
PDF
Advanced C Programming Notes
Leslie Schulte
 
PDF
Storage class
Kathmandu University
 
DOC
Storage classess of C progamming
Appili Vamsi Krishna
 
PPTX
Storage Class Specifiers
Reddhi Basu
 
PPT
memory
teach4uin
 
PPTX
Storage_classes_and_Scope_rules.pptx
CheriviralaNikhil
 
Storage class
Kalaikumar Thangapandi
 
Storage classes
Leela Koneru
 
Storage classes
Leela Koneru
 
Storage classes in c language
tanmaymodi4
 
Storage classes in c language
Tanmay Modi
 
Storage classes
UTTAM VERMA
 
STORAGE CLASSES
sathish sak
 
Storage Class Specifiers in C++
Reddhi Basu
 
Storage classes
Praveen M Jigajinni
 
Storage classes
priyanka jain
 
What is storage class
Isha Aggarwal
 
Latest C Interview Questions and Answers
DaisyWatson5
 
Storage classes
Puneet Rajput
 
Storage Class in C Progrmming
Kamal Acharya
 
Advanced C Programming Notes
Leslie Schulte
 
Storage class
Kathmandu University
 
Storage classess of C progamming
Appili Vamsi Krishna
 
Storage Class Specifiers
Reddhi Basu
 
memory
teach4uin
 
Storage_classes_and_Scope_rules.pptx
CheriviralaNikhil
 
Ad

Recently uploaded (20)

PDF
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Construction of a Thermal Vacuum Chamber for Environment Test of Triple CubeS...
2208441
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Zero Carbon Building Performance standard
BassemOsman1
 
Tunnel Ventilation System in Kanpur Metro
220105053
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Inventory management chapter in automation and robotics.
atisht0104
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 

Storage class

  • 2. STORAGE CLASSES  The storage class determines the part of the memory where the variables would be stored.  The storage class also determines the initial value of the variable.  It is used to define the scope and lifetime of variable.  There are two storage locations in computer,  1. CPU Registers  2.Memory.  A value stored in CPU register can always be accessed faster than the one that is stored in memory.
  • 3. Four types 1.Automatic storage class. 2.Register storage class. 3.Static storage class. 4.External storage class.
  • 4. Automatic  Keywords : Auto  Storage : Memory  Default initial value : Garbage value  Scope : Local/Block scope  Life : Exists as long as the control remains in the block
  • 5. Example for Automatic  void main() { auto x= 20 ; { auto x = 60 ; printf("n x: %d",x); } printf("nx: %d",x); }  OUTPUT :  x: 60 x: 20  NOTE : Two variables are declared in different blocks , so they are treated as different variables
  • 6. Static  Keywords : Static  Storage : Memory  Default initial value : 0  Scope : Local to the block in which the variable is defined.  Life : Value of the variable persists between different function calls.
  • 7. Difference between auto and static class  /*auto class*/ #include<stdio.h> void add(); int main() { add(); add(); add(); add(); return 0; } void add() { auto int i=1; printf("n%d",i); i=i+1;  OUTPUT:- 1 1 1 1  /*static class*/ #include<stdio.h> void add(); int main() { add(); add(); add(); add(); return 0; } void add() { static int i=1; printf("n%d",i); i=i+1; }  OUTPUT:- 1 2 3 4 
  • 8. Previous program explanation  If the storage class is static, then the statement static int i = 1 is executed only once, irrespective of how many times the same function is called.  If the storage class is auto,then the statement auto int i=1 is executed each time where it increments and re-initialize the value of i= 1.  The difference between them is that static variable do not disappear when the function is no longer active. There value persist. If control comes back to the same function again , the static variables have the same values they had last time around.
  • 9. Register  Keywords : Register.  Storage : CPU register.  Default initial value : Garbage value  Scope : Local to the block in which the variable is defined.  Life : Value of the variable persists till the control remains within the block in which
  • 10. Why we need Register Variable ?  Whenever we declare any variable inside C Program then memory will be randomly allocated at particular memory location.  We have to keep track of that memory location. We need to access value at that memory location using ampersand operator/Address Operator i.e (&).  If we store same variable in the register memory then we can access that memory location directly without using the Address operator.  Register variable will be accessed faster than the normal variable thus increasing the operation and program execution. Generally we use register variable as Counter.  Note : It is not applicable for arrays, structures or pointers.
  • 11. External  Keywords : Extern.  Storage : Memory.  Default initial value : 0  Scope : Global  Life : Exists as long as variable is running Retains value within the function
  • 12. Example for Extern  int num = 75 ; void display(); void main() { extern int num ; printf("nNum : %d",num); display(); } void display() { extern int num ; printf("nNum : %d",num); }  OUTPUT:  Num : 75 Num : 75
  • 13. Extern contd… Note :Declaration within the function indicates that the function uses external variable Functions belonging to same source code , does not require declaration (no need to write extern) If variable is defined outside the source code , then declaration using extern keyword is required