SlideShare a Scribd company logo
NITESH KUMAR PANDEY
STORAGE CLASS

 The storage class determines the part of the memory
  where the variable would be stored.
 The storage class also determines the initial value of
  the variable.
 and it used to define the scope and lifetime of
  variable.
 There are two storage location in computer :
   CPU Registers and Memory
CPU REGISTER AND MEMORY

 A value stored in a CPU register can always be
 accessed faster then the one that is stored in
 memory.
TYPES OF STORAGE CLASSES

There are four types of storage classes in C:
i.   Automatic storage class
ii.   Register storage class
iii.  Static storage class
iv.   External storage class
Automatic Storage Class

 Keywords                : auto.
 Storage                  : memory.
 Default initial value     : garbage value.
 Scope                     : local to the block in
                                which the variable is
                                defined.
 Life                     : till the control remains
                                within the block in which
                                the variable is defined.
Example of Automatic Storage Class

#include<stdio.h>
#include<conio.h>
void main()
{
auto int i=1;
{
auto int i=2;
{
auto int i=3;
printf(“n%d”,i);
}
printf(“%d”,i);
}
printf(“%d”,i);
getch();
}

Output:
3 2 1
Register Storage Class

 Keywords                : register.
 Storage                  : CPU Register.
 Default initial value   : garbage value.
 Scope                   : local to the block in
                             which the variable is
                              defined.
 Life                     : till the control remains
                                within the block in which
                                the variable is defined.
Example of Register Storage Class

#include<stdio.h>
#include<conio.h>
void main()
{
register int i;
for(i=1;i<=10;i++)
printf(“ %d",i);
getch();
}
Output:
1 2 3 4 5 6 7 8 9 10
Register Storage Class

 If the microprocessor has 16-bit registers then they
  cannot hold a float value or a double value which
  requires 4bytes(32-bit) and 8 bytes(64-bit)
 If you want to use the register storage class(16-bit
  microprocessor) with float and double variable then
  you won‟t get any error messages. Your compiler
  would treat the variables as auto storage class.
Static Storage Class

 Keywords                : static.
 Storage                  : memory.
 Default initial value     : zero.
 Scope                     : local to the block in
                              which the variable is
                              defined.
 Life                     : value of the variable
                               persists between different
                               function calls.
Dif. b/w auto and static storage class

Automatic                   Static

#include<stdio.h>           #include<stdio.h>
#include<conio.h>           #include<conio.h>
increment();                increment();
void main()                 void main()
{                           {
increment();                increment();
increment();                increment();
increment();                increment();
}                           }
increment()                 increment()
{                           {
auto int i=1;               static int i=1;
printf("%dt",i);           printf("%dt",i);
i++;                        i++;
getch();                    getch();
}                           }
Output:                     Output:
1 1           1             1      2       3
External Storage Class

 Keywords                 : extern.
 Storage                 : memory.
 Default initial value   : zero.
 Scope                   : global.
 Life                     : as long as the program‟s
                             execution doesn‟t come
                              to an end.
• The  different b/w two programs 1st auto and 2nd
static storage class for variable „i‟ the scope of
auto and static both use local to the block in witch
the variable is declared.
• Those program consists two functions main() and
increment().
• The increment() function called from main()
function for three times.
• Each time increment the value of „i‟ and print.
• when variable „i‟ is auto each time increment and
re-initialized to 1.
Example of External Storage Class
#include<stdio.h>
#include<conio.h>
int i =1;
increment();
void main()
{
printf("%dt",i);
increment();
increment();
getch();
}
increment()
{
i++;
printf("%dt",i);
}
Output:
1 2       3
Storage class in C Language
Ad

More Related Content

What's hot (20)

Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
David Livingston J
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
Srichandan Sobhanayak
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
Nitesh Bichwani
 
Data types
Data typesData types
Data types
Zahid Hussain
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
Self employed
 
structured programming
structured programmingstructured programming
structured programming
Ahmad54321
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
Self employed
 
structured programming
structured programmingstructured programming
structured programming
Ahmad54321
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 

Viewers also liked (20)

11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
kapil078
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
Jake Bond
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
kash95
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
Kamal Acharya
 
Storage class
Storage classStorage class
Storage class
Learn By Watch
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
gourav kottawar
 
Memory
MemoryMemory
Memory
Nitesh Kumar Pandey
 
Jdbc
JdbcJdbc
Jdbc
Nitesh Kumar Pandey
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
Arpana shree
 
Arrays
ArraysArrays
Arrays
archikabhatia
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
shalini392
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
Control statements
Control statementsControl statements
Control statements
kamal kotecha
 
Solid waste management ppt
Solid waste management pptSolid waste management ppt
Solid waste management ppt
Pallabi Priyadarsini
 
Storage class
Storage classStorage class
Storage class
Joy Forerver
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
baabtra.com - No. 1 supplier of quality freshers
 
Storage classes
Storage classesStorage classes
Storage classes
Leela Koneru
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
baabtra.com - No. 1 supplier of quality freshers
 
Multi Media Technology
Multi Media TechnologyMulti Media Technology
Multi Media Technology
Ms. BP
 
Operatingsystems lecture2
Operatingsystems lecture2Operatingsystems lecture2
Operatingsystems lecture2
Gaurav Meena
 
Ad

Similar to Storage class in C Language (20)

Storage class
Storage classStorage class
Storage class
Kalaikumar Thangapandi
 
Storage classes
Storage classesStorage classes
Storage classes
Puneet Rajput
 
Storage class
Storage classStorage class
Storage class
Kathmandu University
 
different Storage classse in c programmings.pptx
different Storage classse in c programmings.pptxdifferent Storage classse in c programmings.pptx
different Storage classse in c programmings.pptx
vidhyapm2
 
Storage class
Storage classStorage class
Storage class
MANJULA_AP
 
from java to c
from java to cfrom java to c
from java to c
Võ Hòa
 
What is storage class
What is storage classWhat is storage class
What is storage class
Isha Aggarwal
 
C Storage Classes VSN
C Storage Classes VSNC Storage Classes VSN
C Storage Classes VSN
NITTTR
 
Storage classes
Storage classesStorage classes
Storage classes
Shanmughaneethi Velu
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
Long Cao
 
ppl unit 3.pptx ppl unit 3 usefull can understood
ppl unit 3.pptx ppl unit 3 usefull can understoodppl unit 3.pptx ppl unit 3 usefull can understood
ppl unit 3.pptx ppl unit 3 usefull can understood
divasivavishnu2003
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
CheriviralaNikhil
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
karmuhtam
 
fundamentals of softweare engeneering and programming in C.pptx
fundamentals of softweare engeneering and programming in C.pptxfundamentals of softweare engeneering and programming in C.pptx
fundamentals of softweare engeneering and programming in C.pptx
utsavyadav2006
 
Storage classes
Storage classesStorage classes
Storage classes
Leela Koneru
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
VGaneshKarthikeyan
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
different Storage classse in c programmings.pptx
different Storage classse in c programmings.pptxdifferent Storage classse in c programmings.pptx
different Storage classse in c programmings.pptx
vidhyapm2
 
from java to c
from java to cfrom java to c
from java to c
Võ Hòa
 
What is storage class
What is storage classWhat is storage class
What is storage class
Isha Aggarwal
 
C Storage Classes VSN
C Storage Classes VSNC Storage Classes VSN
C Storage Classes VSN
NITTTR
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
Long Cao
 
ppl unit 3.pptx ppl unit 3 usefull can understood
ppl unit 3.pptx ppl unit 3 usefull can understoodppl unit 3.pptx ppl unit 3 usefull can understood
ppl unit 3.pptx ppl unit 3 usefull can understood
divasivavishnu2003
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
CheriviralaNikhil
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
karmuhtam
 
fundamentals of softweare engeneering and programming in C.pptx
fundamentals of softweare engeneering and programming in C.pptxfundamentals of softweare engeneering and programming in C.pptx
fundamentals of softweare engeneering and programming in C.pptx
utsavyadav2006
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Muhammad Ulhaque
 
Ad

Recently uploaded (20)

Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 

Storage class in C Language

  • 2. STORAGE CLASS  The storage class determines the part of the memory where the variable would be stored.  The storage class also determines the initial value of the variable.  and it used to define the scope and lifetime of variable.  There are two storage location in computer : CPU Registers and Memory
  • 3. CPU REGISTER AND MEMORY  A value stored in a CPU register can always be accessed faster then the one that is stored in memory.
  • 4. TYPES OF STORAGE CLASSES There are four types of storage classes in C: i. Automatic storage class ii. Register storage class iii. Static storage class iv. External storage class
  • 5. Automatic Storage Class  Keywords : auto.  Storage : memory.  Default initial value : garbage value.  Scope : local to the block in which the variable is defined.  Life : till the control remains within the block in which the variable is defined.
  • 6. Example of Automatic Storage Class #include<stdio.h> #include<conio.h> void main() { auto int i=1; { auto int i=2; { auto int i=3; printf(“n%d”,i); } printf(“%d”,i); } printf(“%d”,i); getch(); } Output: 3 2 1
  • 7. Register Storage Class  Keywords : register.  Storage : CPU Register.  Default initial value : garbage value.  Scope : local to the block in which the variable is defined.  Life : till the control remains within the block in which the variable is defined.
  • 8. Example of Register Storage Class #include<stdio.h> #include<conio.h> void main() { register int i; for(i=1;i<=10;i++) printf(“ %d",i); getch(); } Output: 1 2 3 4 5 6 7 8 9 10
  • 9. Register Storage Class  If the microprocessor has 16-bit registers then they cannot hold a float value or a double value which requires 4bytes(32-bit) and 8 bytes(64-bit)  If you want to use the register storage class(16-bit microprocessor) with float and double variable then you won‟t get any error messages. Your compiler would treat the variables as auto storage class.
  • 10. Static Storage Class  Keywords : static.  Storage : memory.  Default initial value : zero.  Scope : local to the block in which the variable is defined.  Life : value of the variable persists between different function calls.
  • 11. Dif. b/w auto and static storage class Automatic Static #include<stdio.h> #include<stdio.h> #include<conio.h> #include<conio.h> increment(); increment(); void main() void main() { { increment(); increment(); increment(); increment(); increment(); increment(); } } increment() increment() { { auto int i=1; static int i=1; printf("%dt",i); printf("%dt",i); i++; i++; getch(); getch(); } } Output: Output: 1 1 1 1 2 3
  • 12. External Storage Class  Keywords : extern.  Storage : memory.  Default initial value : zero.  Scope : global.  Life : as long as the program‟s execution doesn‟t come to an end.
  • 13. • The different b/w two programs 1st auto and 2nd static storage class for variable „i‟ the scope of auto and static both use local to the block in witch the variable is declared. • Those program consists two functions main() and increment(). • The increment() function called from main() function for three times. • Each time increment the value of „i‟ and print. • when variable „i‟ is auto each time increment and re-initialized to 1.
  • 14. Example of External Storage Class #include<stdio.h> #include<conio.h> int i =1; increment(); void main() { printf("%dt",i); increment(); increment(); getch(); } increment() { i++; printf("%dt",i); } Output: 1 2 3
  翻译: