SlideShare a Scribd company logo
11
Most read
12
Most read
15
Most read
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
Storage classes in c language
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

PPTX
Storage class in C Language
PPTX
Storage classes in C
PDF
Problem Solving Techniques and Introduction to C
PDF
A SAMPLE PROJECT PROPOSAL FOR FUNDING TO PROSPECTIVE DONORS.pdf
PPT
Basics of c++ Programming Language
PPTX
Function in C program
PPT
Modes Of Transfer in Input/Output Organization
PPTX
4. unit 3 reflective level bigge and hunt
Storage class in C Language
Storage classes in C
Problem Solving Techniques and Introduction to C
A SAMPLE PROJECT PROPOSAL FOR FUNDING TO PROSPECTIVE DONORS.pdf
Basics of c++ Programming Language
Function in C program
Modes Of Transfer in Input/Output Organization
4. unit 3 reflective level bigge and hunt

What's hot (20)

PPT
Variables in C Programming
PPTX
Pointers in c++
PPT
Operators in C++
PPTX
Union in C programming
PPT
Constants in C Programming
PPTX
This pointer
PPTX
Storage class in c
PPTX
Datatype in c++ unit 3 -topic 2
PPTX
User defined functions in C
PPT
FUNCTIONS IN c++ PPT
PPT
Operator Overloading
PPTX
Dynamic memory allocation in c
PPTX
Variables in C and C++ Language
PPTX
Constructor and Types of Constructors
PPTX
Constructors and destructors
PPTX
Presentation on Function in C Programming
PPTX
PPTX
Union in c language
PPTX
File in C language
Variables in C Programming
Pointers in c++
Operators in C++
Union in C programming
Constants in C Programming
This pointer
Storage class in c
Datatype in c++ unit 3 -topic 2
User defined functions in C
FUNCTIONS IN c++ PPT
Operator Overloading
Dynamic memory allocation in c
Variables in C and C++ Language
Constructor and Types of Constructors
Constructors and destructors
Presentation on Function in C Programming
Union in c language
File in C language
Ad

Similar to Storage classes in c language (20)

PPTX
Storage classes
PPTX
Storage Class in C Progrmming
PPTX
Storage classes
DOCX
Storage class
PPTX
Storage classes
DOC
Storage classess of C progamming
PPTX
Storage Class Specifiers in C++
PPT
Storage classes
PPTX
Storage class
PPT
Storage classes
PDF
Latest C Interview Questions and Answers
PDF
Advanced C Programming Notes
PPTX
Storage Class Specifiers
PPT
Storage classes
PPTX
STORAGE CLASS.pptx
PPTX
Storage_classes_and_Scope_rules.pptx
PPT
Lecture 13 - Storage Classes
DOC
What is storage class
PPT
STORAGE CLASSES
DOC
5.program structure
Storage classes
Storage Class in C Progrmming
Storage classes
Storage class
Storage classes
Storage classess of C progamming
Storage Class Specifiers in C++
Storage classes
Storage class
Storage classes
Latest C Interview Questions and Answers
Advanced C Programming Notes
Storage Class Specifiers
Storage classes
STORAGE CLASS.pptx
Storage_classes_and_Scope_rules.pptx
Lecture 13 - Storage Classes
What is storage class
STORAGE CLASSES
5.program structure
Ad

More from tanmaymodi4 (10)

PDF
Cryptocurrency
PPTX
Pointers in c v5 12102017 1
PPTX
Operators and expressions in c language
PPTX
Loops in c language
PPTX
Functions in c language
PPTX
Dynamic memory allocation in c language
PPTX
Arrays in c language
PPTX
Decision statements in c language
PPTX
Preprocessor directives in c language
PPTX
Structures in c language
Cryptocurrency
Pointers in c v5 12102017 1
Operators and expressions in c language
Loops in c language
Functions in c language
Dynamic memory allocation in c language
Arrays in c language
Decision statements in c language
Preprocessor directives in c language
Structures in c language

Recently uploaded (20)

PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
My India Quiz Book_20210205121199924.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
1_English_Language_Set_2.pdf probationary
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
HVAC Specification 2024 according to central public works department
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
B.Sc. DS Unit 2 Software Engineering.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Chinmaya Tiranga quiz Grand Finale.pdf
Computer Architecture Input Output Memory.pptx
My India Quiz Book_20210205121199924.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
1_English_Language_Set_2.pdf probationary
LDMMIA Reiki Yoga Finals Review Spring Summer
HVAC Specification 2024 according to central public works department
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
Virtual and Augmented Reality in Current Scenario
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Vision Prelims GS PYQ Analysis 2011-2022 www.upscpdf.com.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

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
  • 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