SlideShare uma empresa Scribd logo
1 de 15
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

Mais conteúdo relacionado

Mais procurados

constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
Sahithi Naraparaju
 

Mais procurados (20)

Storage class in c
Storage class in cStorage class in c
Storage class in c
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
Structure in C
Structure in CStructure in C
Structure in C
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Data types in C
Data types in CData types in C
Data types in C
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 

Destaque

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
 
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
 
Operatingsystems lecture2
Operatingsystems lecture2Operatingsystems lecture2
Operatingsystems lecture2
Gaurav Meena
 

Destaque (20)

11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Storage class
Storage classStorage class
Storage class
 
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
 
Memory
MemoryMemory
Memory
 
Jdbc
JdbcJdbc
Jdbc
 
Enumerated data types in C
Enumerated data types in CEnumerated data types in C
Enumerated data types in C
 
Arrays
ArraysArrays
Arrays
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Control statements
Control statementsControl statements
Control statements
 
Solid waste management ppt
Solid waste management pptSolid waste management ppt
Solid waste management ppt
 
Storage class
Storage classStorage class
Storage class
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Storage classes
Storage classesStorage classes
Storage classes
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Multi Media Technology
Multi Media TechnologyMulti Media Technology
Multi Media Technology
 
Operatingsystems lecture2
Operatingsystems lecture2Operatingsystems lecture2
Operatingsystems lecture2
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 

Semelhante a Storage class in C Language

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
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
Long Cao
 
storage class
storage classstorage class
storage class
student
 

Semelhante a Storage class in C Language (20)

Storage class
Storage classStorage class
Storage class
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage class
Storage classStorage class
Storage class
 
Storage class
Storage classStorage class
Storage class
 
from java to c
from java to cfrom java to c
from java to c
 
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
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Getting Started Cpp
Getting Started CppGetting Started Cpp
Getting Started Cpp
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
Storage classes
Storage classesStorage classes
Storage classes
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
 
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...
 
storage class
storage classstorage class
storage class
 
Unit iii
Unit iiiUnit iii
Unit iii
 
C++ theory
C++ theoryC++ theory
C++ theory
 

Último

Último (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 

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