SlideShare a Scribd company logo
1 of 15
Storage Classes
in C
Introduction
 Variables declared in C programs are
different than other programming
languages.
 Can use the same variable names in the
C program in separate blocks.
 When we declare a variable,it is
available only to a specific part or block
of the program.
 Remaining block or other functions
cannot access the variable.
 Variables declared within functions are
called local variables and those declared
outside are called external or global
variables.
Definition
Scope of variables:
 The area or scope of the C program from
where the variable can be accessed.
 The area or scope of the variable
depends on its storage class i.e. Where
and how it is declared.
The storage class of a variable tells the
compiler:
i)the storage area of the variable
ii)the initial value of the variable.
Iii)the scope of the variable.
Iv) the life of the variable i.e. How long the
variable would be active in the program.
 Variables declared in C can have any
one of the four storage classes:
Automatic
External
Static
Register
Lifetime of a Variable
 Every variable has a lifetime i.e. Its time
duration during which its status is active
in the program.
 The time gap between its declaration
and ckeanup.
 The lifetime depends upon the storage
class.
 For eg,auto variable gets destroyed
immediately when the function execution
is over,whereas static variable remains in
the memory.
Visibility of a Variable
 It defines the scope of a variable.
 The scope is of two types:
◦ Local scope
◦ Global scope
Global is recognized throughout the
program,whereas the local variable scope is
limited to the declaration block
Automatic variables
 The auto keyword is applied to all
local variables automatically.
 It is the default storage class that is
why it is known as automatic variable.
 the scope of the variable is local to the
block in which it is defined,available
only to the current block or program.
 The vanish after the block of code
finishes executing.
Example:
Register Variables
 The register variable allocates
memory in register than RAM.
 It has a faster access than other
variables.
 CPU registers are limited,hence
cannot declare more register
variables.
 It is recommended to use register
variable only for quick access such as
in counter.
Note: We can't get the address of
Example
void main()
{
register int m=1;
clrscr();
for (;m<=5;m++)
printf(“t %d”,m);
}
1 2 3 4 5
Static variables
 The static variable is initialized only
once and exists till the end of the
program.
 It retains its value between multiple
functions call.
 The static variable has the default
value 0 which is provided by
compiler,initialised once,it is never
reinitialized.
 Can be used to count how many times
Example
External Variable
 The extern variable is visible to all the
programs.
 It is used if two or more files are
sharing same variable or function.
 In case in aprogram where both
external and auto variables have been
declared with the same name,the first
priority is given to the auto variable.
 Variable defined at other place,other
than the place where it is declared.
Example:
int j=4;
void main() Output:
{
extern int j;
clrscr();
j=j*3;
printf(“ j=%d”,j);
fun();
printf(“n j=%d”,j);
}
fun()
{
j=j*j;
}
J=12
J=144

More Related Content

What's hot

Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++Reddhi Basu
 
Storage class in c
Storage class in cStorage class in c
Storage class in ckash95
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage classkapil078
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controlsvinay arora
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 

What's hot (19)

Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Storage classes
Storage classesStorage classes
Storage classes
 
STORAGE CLASSES
STORAGE CLASSESSTORAGE CLASSES
STORAGE CLASSES
 
C language
C languageC language
C language
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Storage class
Storage classStorage class
Storage class
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
C language presentation
C language presentationC language presentation
C language presentation
 

Similar to Storage classes in c language

Similar to Storage classes in c language (20)

Storage classes
Storage classesStorage classes
Storage classes
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage class
Storage classStorage class
Storage class
 
Storage classes
Storage classesStorage classes
Storage classes
 
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
 
Advanced C Programming Notes
Advanced C Programming NotesAdvanced C Programming Notes
Advanced C Programming Notes
 
Storage Class Specifiers
Storage Class SpecifiersStorage Class Specifiers
Storage Class Specifiers
 
Storage classes
Storage classesStorage classes
Storage classes
 
STORAGE CLASS.pptx
STORAGE CLASS.pptxSTORAGE CLASS.pptx
STORAGE CLASS.pptx
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
5.program structure
5.program structure5.program structure
5.program structure
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
01 Variables
01 Variables01 Variables
01 Variables
 
Ch07
Ch07Ch07
Ch07
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
C language updated
C language updatedC language updated
C language updated
 

More from Tanmay Modi

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguageTanmay Modi
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c languageTanmay Modi
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Generations of computers
Generations of computersGenerations of computers
Generations of computersTanmay Modi
 
Union in c language
Union in c languageUnion in c language
Union in c languageTanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languageTanmay Modi
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languageTanmay Modi
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017Tanmay Modi
 

More from Tanmay Modi (12)

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Generations of computers
Generations of computersGenerations of computers
Generations of computers
 
Union in c language
Union in c languageUnion in c language
Union in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017
 
Cryptocurrency
Cryptocurrency Cryptocurrency
Cryptocurrency
 

Recently uploaded

Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

Storage classes in c language

  • 2. Introduction  Variables declared in C programs are different than other programming languages.  Can use the same variable names in the C program in separate blocks.  When we declare a variable,it is available only to a specific part or block of the program.  Remaining block or other functions cannot access the variable.  Variables declared within functions are called local variables and those declared outside are called external or global variables.
  • 3. Definition Scope of variables:  The area or scope of the C program from where the variable can be accessed.  The area or scope of the variable depends on its storage class i.e. Where and how it is declared. The storage class of a variable tells the compiler: i)the storage area of the variable ii)the initial value of the variable. Iii)the scope of the variable. Iv) the life of the variable i.e. How long the variable would be active in the program.
  • 4.  Variables declared in C can have any one of the four storage classes: Automatic External Static Register
  • 5. Lifetime of a Variable  Every variable has a lifetime i.e. Its time duration during which its status is active in the program.  The time gap between its declaration and ckeanup.  The lifetime depends upon the storage class.  For eg,auto variable gets destroyed immediately when the function execution is over,whereas static variable remains in the memory.
  • 6. Visibility of a Variable  It defines the scope of a variable.  The scope is of two types: ◦ Local scope ◦ Global scope Global is recognized throughout the program,whereas the local variable scope is limited to the declaration block
  • 7.
  • 8. Automatic variables  The auto keyword is applied to all local variables automatically.  It is the default storage class that is why it is known as automatic variable.  the scope of the variable is local to the block in which it is defined,available only to the current block or program.  The vanish after the block of code finishes executing.
  • 10. Register Variables  The register variable allocates memory in register than RAM.  It has a faster access than other variables.  CPU registers are limited,hence cannot declare more register variables.  It is recommended to use register variable only for quick access such as in counter. Note: We can't get the address of
  • 11. Example void main() { register int m=1; clrscr(); for (;m<=5;m++) printf(“t %d”,m); } 1 2 3 4 5
  • 12. Static variables  The static variable is initialized only once and exists till the end of the program.  It retains its value between multiple functions call.  The static variable has the default value 0 which is provided by compiler,initialised once,it is never reinitialized.  Can be used to count how many times
  • 14. External Variable  The extern variable is visible to all the programs.  It is used if two or more files are sharing same variable or function.  In case in aprogram where both external and auto variables have been declared with the same name,the first priority is given to the auto variable.  Variable defined at other place,other than the place where it is declared.
  • 15. Example: int j=4; void main() Output: { extern int j; clrscr(); j=j*3; printf(“ j=%d”,j); fun(); printf(“n j=%d”,j); } fun() { j=j*j; } J=12 J=144