SlideShare a Scribd company logo
• A storage class defines the scope , visibility and
life time of variables and/or functions within a C
Program.
• There are following storage classes which can be
used in a C Program
1. Automatic variables
2. Register variables
3. Static variables
4. Extern variables
• Life Time – Life time of any variable is the time for which
the particular variable outlives in memory during running
of the program.
• Scope –A variable may be in the memory but may not be
accessible though. So, the area of our program where we
can actually access our entity (variable in this case) is the
scope of that variable.
• . The visibility of a variable determines how much of the
rest of the program can access that variable. You can
arrange that a variable is visible only within one part of one
function, or in one function, or in one source file, or
anywhere in the program. (
•
Automatic variable - Storage Class
• It is declared inside function where it is used
• They are created when function is called and destroyed
automatically when the function is exited
• They are local to function and called as private variables
• It is also called as local or internal variables
• Main()
{
int number;
}
• auto is the default storage class for all local variables no
need to use the keyword auto
Illustration how automatic variables
work
Void function1(void)
Void function2(void)
Main()
{
int m = 1000;
function2();
printf( “%dn”, m);
}
Void function1(void)
{
int m = 10;
printf(“%dn”, m);
}
Void function2(void)
{
int m= 100;
function1();
printf(“%d n”,m);
}
Output
10
100
1000
External variable
• These variables are both alive and active throughout the entire program
• It is also called global variables
• It can be access by any function in the program
• It is declared outside the function
• Extern is the keyword used for this type of class
• When you have multiple files and you define a global variable or function,
which will also be used in other files, then extern will be used in another
file to provide the reference of defined variable or function. Just for
understanding, extern is used to declare a global variable or function in
another file.
• The extern modifier is most commonly used when there are two or more
files sharing the same global variables or functions as explained below.
•
#include <stdio.h>
int count ;
extern void write_extern();
main()
{ count = 5;
write_extern();
}
Main.c
#include <stdio.h>
extern int count;
void write_extern(void)
{ printf("count is %dn", count);
}
Suppot.c
Compile
Gcc main.c support.c
Output is 5
Static - Storage Class
• It persists at the function until the end of the program
• The keyword static is used for declaration
– Static int x;
– Static float y;
• Static may be either internal type or external type
• Internal means it is declared inside the function
• The scope is us up to the end of the function
• It is similar to auto variable
• It is used to retain the values between function calls
Program to illustrate the properties
of a static variables
Void stat(void)
Main()
{
int il
for (i=1;i<=3;i++)
stat();
}
Void stat(void)
{static int x=0;
X=x+1;
Printf(“x=%dn”,x);
Output
X=1
X=2
X=3
Register - Storage Class
• Register is used to define local variables that should be stored in a register
instead of RAM.
• This means that the variable has a maximum size equal to the register size
(usually one word) and cant have the unary '&' operator applied to it (as it
does not have a memory location).
{
register int Miles;
}
• Register should only be used for variables that require quick access - such
as counters.
• It should also be noted that defining 'register' goes not mean that the
variable will be stored in a register.
• It means that it MIGHT be stored in a register - depending on hardware
and implementation restrictions.
Type casting
• C allows programmers to perform typecasting by placing the type name in parentheses and
placing this in front of the value.
•
• For instance
•
• main()
{
float a;
a = (float)5 / 3;
}
•
• gives result as 1.666666 . This is because the integer 5 is converted to floating point value
before division and the operation between float and integer results in float.
•
• From the above it is clear that the usage of typecasting is to make a variable of one type, act
like another type for one single operation.
• So by using this ability of typecasting it is possible for create ASCII characters by typecasting
integer to its character equivalent.
Type definition
• This feature allows user to define new data
type that are equivalent to existing data types
• Once the new data type has been established
, the new variable, array and structure can be
declared in terms of the new data type
• The format is
– Typedef type new-type
– Eg: typedef int age
– age is also a datatype which hold int value
• Age male , female;
• male is a variable name with the data type of
age which equivalent to the int data type
• This type def is used with structure also

More Related Content

PPTX
Storage class in c
PPTX
Storage classes
PPTX
Storage classes
PPTX
Storage classes in C
PPT
cs8251 unit 1 ppt
PDF
Storage Classes.pdf DJJKLF DKFF DSLKF. DSF; FD
PPT
S torage class in C
DOCX
Storage class
Storage class in c
Storage classes
Storage classes
Storage classes in C
cs8251 unit 1 ppt
Storage Classes.pdf DJJKLF DKFF DSLKF. DSF; FD
S torage class in C
Storage class

Similar to STORAGE CLASS.pptx (20)

PPT
Lecture 13 - Storage Classes
PDF
Terms and Definitions.pdf
DOC
What is storage class
DOC
Storage classess of C progamming
PDF
Storage classes arrays & functions in C Language
DOC
5.program structure
PPT
Storage classes
PPTX
Storage classes in C
PPTX
Storage class
PPTX
Storage classes
PPTX
C language updated
PPTX
C language
PPTX
Storage class
PPTX
Storage_classes_and_Scope_rules.pptx
PPTX
Storage classes in c language
PPTX
Storage classes in c language
PPTX
C language presentation
PPTX
Storage Class in C Progrmming
PPT
Storage classes
PPT
Lecture 13 - Storage Classes
Terms and Definitions.pdf
What is storage class
Storage classess of C progamming
Storage classes arrays & functions in C Language
5.program structure
Storage classes
Storage classes in C
Storage class
Storage classes
C language updated
C language
Storage class
Storage_classes_and_Scope_rules.pptx
Storage classes in c language
Storage classes in c language
C language presentation
Storage Class in C Progrmming
Storage classes
Ad

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PPTX
Introduction to Building Materials
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
advance database management system book.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Cell Types and Its function , kingdom of life
Trump Administration's workforce development strategy
Introduction to Building Materials
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
What if we spent less time fighting change, and more time building what’s rig...
LDMMIA Reiki Yoga Finals Review Spring Summer
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Final Presentation General Medicine 03-08-2024.pptx
advance database management system book.pdf
Complications of Minimal Access Surgery at WLH
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
UNIT III MENTAL HEALTH NURSING ASSESSMENT
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
202450812 BayCHI UCSC-SV 20250812 v17.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Indian roads congress 037 - 2012 Flexible pavement
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Cell Types and Its function , kingdom of life
Ad

STORAGE CLASS.pptx

  • 1. • A storage class defines the scope , visibility and life time of variables and/or functions within a C Program. • There are following storage classes which can be used in a C Program 1. Automatic variables 2. Register variables 3. Static variables 4. Extern variables
  • 2. • Life Time – Life time of any variable is the time for which the particular variable outlives in memory during running of the program. • Scope –A variable may be in the memory but may not be accessible though. So, the area of our program where we can actually access our entity (variable in this case) is the scope of that variable. • . The visibility of a variable determines how much of the rest of the program can access that variable. You can arrange that a variable is visible only within one part of one function, or in one function, or in one source file, or anywhere in the program. ( •
  • 3. Automatic variable - Storage Class • It is declared inside function where it is used • They are created when function is called and destroyed automatically when the function is exited • They are local to function and called as private variables • It is also called as local or internal variables • Main() { int number; } • auto is the default storage class for all local variables no need to use the keyword auto
  • 4. Illustration how automatic variables work Void function1(void) Void function2(void) Main() { int m = 1000; function2(); printf( “%dn”, m); } Void function1(void) { int m = 10; printf(“%dn”, m); } Void function2(void) { int m= 100; function1(); printf(“%d n”,m); } Output 10 100 1000
  • 5. External variable • These variables are both alive and active throughout the entire program • It is also called global variables • It can be access by any function in the program • It is declared outside the function • Extern is the keyword used for this type of class • When you have multiple files and you define a global variable or function, which will also be used in other files, then extern will be used in another file to provide the reference of defined variable or function. Just for understanding, extern is used to declare a global variable or function in another file. • The extern modifier is most commonly used when there are two or more files sharing the same global variables or functions as explained below. •
  • 6. #include <stdio.h> int count ; extern void write_extern(); main() { count = 5; write_extern(); } Main.c #include <stdio.h> extern int count; void write_extern(void) { printf("count is %dn", count); } Suppot.c Compile Gcc main.c support.c Output is 5
  • 7. Static - Storage Class • It persists at the function until the end of the program • The keyword static is used for declaration – Static int x; – Static float y; • Static may be either internal type or external type • Internal means it is declared inside the function • The scope is us up to the end of the function • It is similar to auto variable • It is used to retain the values between function calls
  • 8. Program to illustrate the properties of a static variables Void stat(void) Main() { int il for (i=1;i<=3;i++) stat(); } Void stat(void) {static int x=0; X=x+1; Printf(“x=%dn”,x); Output X=1 X=2 X=3
  • 9. Register - Storage Class • Register is used to define local variables that should be stored in a register instead of RAM. • This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary '&' operator applied to it (as it does not have a memory location). { register int Miles; } • Register should only be used for variables that require quick access - such as counters. • It should also be noted that defining 'register' goes not mean that the variable will be stored in a register. • It means that it MIGHT be stored in a register - depending on hardware and implementation restrictions.
  • 10. Type casting • C allows programmers to perform typecasting by placing the type name in parentheses and placing this in front of the value. • • For instance • • main() { float a; a = (float)5 / 3; } • • gives result as 1.666666 . This is because the integer 5 is converted to floating point value before division and the operation between float and integer results in float. • • From the above it is clear that the usage of typecasting is to make a variable of one type, act like another type for one single operation. • So by using this ability of typecasting it is possible for create ASCII characters by typecasting integer to its character equivalent.
  • 11. Type definition • This feature allows user to define new data type that are equivalent to existing data types • Once the new data type has been established , the new variable, array and structure can be declared in terms of the new data type • The format is – Typedef type new-type – Eg: typedef int age – age is also a datatype which hold int value
  • 12. • Age male , female; • male is a variable name with the data type of age which equivalent to the int data type • This type def is used with structure also