SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (20)

Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Strings
StringsStrings
Strings
 
C language ppt
C language pptC language ppt
C language ppt
 
C tokens
C tokensC tokens
C tokens
 
String functions in C
String functions in CString functions in C
String functions in C
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Type conversion
Type conversionType conversion
Type conversion
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Functions in c
Functions in cFunctions in c
Functions in c
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 

En vedette

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
 

En vedette (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
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
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
 

Similaire à 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
 

Similaire à 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
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Dernier (20)

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...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
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
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

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