SlideShare a Scribd company logo
1 of 15
STORAGE CLASSES
http://computerprogramminginclanguage.blogspot.com/
STORAGE CLASSES
 Introduction
 Types of storage classes
 Scope, visibility and lifetime of storage classes
INTRODUCTION
 To declare and define a variable we need to
specify the datatype. But , to fully declare a
variable, it is also important to specify the
storage class.
 If we don’t specify a storage class of a variable in
it’s declaration, the compiler will assume a
storage class depending on the context of the
variable is used. i.e., each variable has a specified
default storage class
 Variables are generally stored in 2 locations
 Memory
 CPU registers
INTRODUCTION CONTINUE…
 By Using Storage class we come to know the
following
 Where the variable would be stored.
 What will be the initial value of the variable, if the
initial value not specified then what is the default
value.
 What is the scope of the variable, i.e., in which
functions the value of the variable would be
available.
 What is the life time of the variable, i.e., how long
would be the variable exist.
TYPES OF STORAGE CLASSES
 Automatic Variables
 External Variables
 Static Variables
 Register Variables
AUTOMATIC VARIABLES
 Automatic variables are declared inside a
function(block) in which they are used.
 Keyword used to declare a automatic variable is
auto .
 Auto variables are stored in memory.
 Default initial values is garbage value.
 Scope is local to the block/function in which they
are declared.
 Lifetime of auto variable is till the end of the
function in which the variable is defined
 These are also referred as internal or local
variables
AUTOMATIC VARIABLES
CONTINUE…
 void main()
 {
 auto int i;
 printf(“ i: %d”,i);
 }
 Output: GarbageValue(Unexpected Value)
EXTERNAL VARIABLES
 External variables are declared outside all
functions, so that they are available to all the
functions.
 Keyword used to declare external variable is
extern.
 Extern variables are stored in memory.
 Default initial value is zero.
 Scope is global
 Lifetime of extern variable is as long as the
program is executed.
 These are also referred as global variables
EXTERAL VARIABLES CONTINUE…
 int i;
 extern int i;
 void main()
 {
 printf(“ i: %d”,i);
 }
 Output: 0
STATIC VARIABLES
 Static variables can declared either internal or
external .
 Keyword used to declare static variable is static.
 Extern variables are stored in memory.
 Default initial values is zero.
 Scope is global/local based on the declaration.
 Lifetime of internal static variable is local to the
function or external static variables is as long as
the program is executed.
 Static variables can be initialized only once
STATIC VARIABLES CONTINUE…
 void main()
 {
 void increment();
 increment();
 increment();
 increment();
 }
 void increment()
 {
 static int i=1; //int I or auto int I;
 printf(“ i: %d”,i);
 i++;
 }
 Output: i=1 i=2 i=3
REGISTER VARIABLES
 Register variables can declared inside a
function .
 Keyword used to declare static variable is
register.
 Extern variables are stored in CPU registers.
 Register access is much faster than a memory
access, by keeping frequently accessed variables
like looping variable(iteration) in the register
leads to faster execution of a program.
REGISTER VARIABLES CONTINUE…
 Default initial values is garbage value.
 Scope is local to the block .
 Lifetime of variable is with in the block.
REGISTER VARIABLES CONTINUE…
 void main()
 {
 register int i;
 for(i=1;i<=5;i++)
 printf(“ i: %d”,i);
 }
 Output: i:1 i:2 i:3 i:4 i:5
 /* Not sure the variable is stored in register,
because it is limited*/
Storage
Class
Keyword Storage Default
initial
value
Scope Lifetime
Automatic auto memory Garbage Local to
the block
With in the block
External extern memory Zero Global Till the end of
program exe
Static static memory Zero Local Value of the
variable persists
b/w diff. function
calls
Register register CPU
register
Garbage Local to
the block
With in the block
OVERVIEW

More Related Content

What's hot

Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in cyazad dumasia
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmigAppili Vamsi Krishna
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and StringTasnima Hamid
 
C Pointers
C PointersC Pointers
C Pointersomukhtar
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C Self employed
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming Kamal Acharya
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage classkapil078
 
Types of function call
Types of function callTypes of function call
Types of function callArijitDhali
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in cPrabhu Govind
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7sumitbardhan
 

What's hot (20)

Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
C Pointers
C PointersC Pointers
C Pointers
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
class and objects
class and objectsclass and objects
class and objects
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Function in C
Function in CFunction in C
Function in C
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Function in c
Function in cFunction in c
Function in c
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 

Viewers also liked

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
Storage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System ImpactsStorage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System ImpactsZhichao Liang
 
Storage Class Memory: Learning from 3D NAND
Storage Class Memory: Learning from 3D NANDStorage Class Memory: Learning from 3D NAND
Storage Class Memory: Learning from 3D NANDWestern Digital
 
3D Xpoint memory technology
3D Xpoint memory technology3D Xpoint memory technology
3D Xpoint memory technologyNITESH RAI
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++Reddhi Basu
 
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage Comparison
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage ComparisonIntel and DataStax: 3D XPoint and NVME Technology Cassandra Storage Comparison
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage ComparisonDataStax Academy
 

Viewers also liked (8)

Using Storage Class Memory
Using Storage Class MemoryUsing Storage Class Memory
Using Storage Class Memory
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
Storage class memory
Storage class memoryStorage class memory
Storage class memory
 
Storage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System ImpactsStorage Class Memory: Technology Overview & System Impacts
Storage Class Memory: Technology Overview & System Impacts
 
Storage Class Memory: Learning from 3D NAND
Storage Class Memory: Learning from 3D NANDStorage Class Memory: Learning from 3D NAND
Storage Class Memory: Learning from 3D NAND
 
3D Xpoint memory technology
3D Xpoint memory technology3D Xpoint memory technology
3D Xpoint memory technology
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage Comparison
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage ComparisonIntel and DataStax: 3D XPoint and NVME Technology Cassandra Storage Comparison
Intel and DataStax: 3D XPoint and NVME Technology Cassandra Storage Comparison
 

Similar to Storage classes

What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
C Storage Classes VSN
C Storage Classes VSNC Storage Classes VSN
C Storage Classes VSNNITTTR
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and AnswersDaisyWatson5
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languageTanmay Modi
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxCheriviralaNikhil
 
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 LanguageJenish Bhavsar
 
Advanced C Programming Notes
Advanced C Programming NotesAdvanced C Programming Notes
Advanced C Programming NotesLeslie Schulte
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Ahmad55ali
 

Similar to Storage classes (20)

Storage classes
Storage classesStorage classes
Storage classes
 
Storage class
Storage classStorage class
Storage class
 
Storage classes
Storage classesStorage classes
Storage classes
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Storage classes
Storage classesStorage classes
Storage classes
 
C Storage Classes VSN
C Storage Classes VSNC Storage Classes VSN
C Storage Classes VSN
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
Storage classes
Storage classesStorage classes
Storage classes
 
Latest C Interview Questions and Answers
Latest C Interview Questions and AnswersLatest C Interview Questions and Answers
Latest C Interview Questions and Answers
 
5.program structure
5.program structure5.program structure
5.program structure
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Storage class
Storage classStorage class
Storage class
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
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
 
Storage class
Storage classStorage class
Storage class
 
Storage classes
Storage classesStorage classes
Storage classes
 
Advanced C Programming Notes
Advanced C Programming NotesAdvanced C Programming Notes
Advanced C Programming Notes
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
 
Functions in c
Functions in cFunctions in c
Functions in c
 

Recently uploaded

ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

Storage classes

  • 2. STORAGE CLASSES  Introduction  Types of storage classes  Scope, visibility and lifetime of storage classes
  • 3. INTRODUCTION  To declare and define a variable we need to specify the datatype. But , to fully declare a variable, it is also important to specify the storage class.  If we don’t specify a storage class of a variable in it’s declaration, the compiler will assume a storage class depending on the context of the variable is used. i.e., each variable has a specified default storage class  Variables are generally stored in 2 locations  Memory  CPU registers
  • 4. INTRODUCTION CONTINUE…  By Using Storage class we come to know the following  Where the variable would be stored.  What will be the initial value of the variable, if the initial value not specified then what is the default value.  What is the scope of the variable, i.e., in which functions the value of the variable would be available.  What is the life time of the variable, i.e., how long would be the variable exist.
  • 5. TYPES OF STORAGE CLASSES  Automatic Variables  External Variables  Static Variables  Register Variables
  • 6. AUTOMATIC VARIABLES  Automatic variables are declared inside a function(block) in which they are used.  Keyword used to declare a automatic variable is auto .  Auto variables are stored in memory.  Default initial values is garbage value.  Scope is local to the block/function in which they are declared.  Lifetime of auto variable is till the end of the function in which the variable is defined  These are also referred as internal or local variables
  • 7. AUTOMATIC VARIABLES CONTINUE…  void main()  {  auto int i;  printf(“ i: %d”,i);  }  Output: GarbageValue(Unexpected Value)
  • 8. EXTERNAL VARIABLES  External variables are declared outside all functions, so that they are available to all the functions.  Keyword used to declare external variable is extern.  Extern variables are stored in memory.  Default initial value is zero.  Scope is global  Lifetime of extern variable is as long as the program is executed.  These are also referred as global variables
  • 9. EXTERAL VARIABLES CONTINUE…  int i;  extern int i;  void main()  {  printf(“ i: %d”,i);  }  Output: 0
  • 10. STATIC VARIABLES  Static variables can declared either internal or external .  Keyword used to declare static variable is static.  Extern variables are stored in memory.  Default initial values is zero.  Scope is global/local based on the declaration.  Lifetime of internal static variable is local to the function or external static variables is as long as the program is executed.  Static variables can be initialized only once
  • 11. STATIC VARIABLES CONTINUE…  void main()  {  void increment();  increment();  increment();  increment();  }  void increment()  {  static int i=1; //int I or auto int I;  printf(“ i: %d”,i);  i++;  }  Output: i=1 i=2 i=3
  • 12. REGISTER VARIABLES  Register variables can declared inside a function .  Keyword used to declare static variable is register.  Extern variables are stored in CPU registers.  Register access is much faster than a memory access, by keeping frequently accessed variables like looping variable(iteration) in the register leads to faster execution of a program.
  • 13. REGISTER VARIABLES CONTINUE…  Default initial values is garbage value.  Scope is local to the block .  Lifetime of variable is with in the block.
  • 14. REGISTER VARIABLES CONTINUE…  void main()  {  register int i;  for(i=1;i<=5;i++)  printf(“ i: %d”,i);  }  Output: i:1 i:2 i:3 i:4 i:5  /* Not sure the variable is stored in register, because it is limited*/
  • 15. Storage Class Keyword Storage Default initial value Scope Lifetime Automatic auto memory Garbage Local to the block With in the block External extern memory Zero Global Till the end of program exe Static static memory Zero Local Value of the variable persists b/w diff. function calls Register register CPU register Garbage Local to the block With in the block OVERVIEW