SlideShare a Scribd company logo
1 of 12
• 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

Similar to STORAGE CLASS.pptx

Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Ahmad55ali
 
Programming Language
Programming  LanguageProgramming  Language
Programming LanguageAdeel Hamid
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C Self employed
 
What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languageTanmay Modi
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxSKUP1
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxLECO9
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxnoonoboom
 

Similar to STORAGE CLASS.pptx (20)

cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
c-functions.ppt
c-functions.pptc-functions.ppt
c-functions.ppt
 
Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,Global variables, sorting static variables,function and arrays,
Global variables, sorting static variables,function and arrays,
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage classes
Storage classesStorage classes
Storage classes
 
Programming Language
Programming  LanguageProgramming  Language
Programming Language
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
C- language Lecture 6
C- language Lecture 6C- language Lecture 6
C- language Lecture 6
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Terms and Definitions.pdf
Terms and Definitions.pdfTerms and Definitions.pdf
Terms and Definitions.pdf
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
 
Functions
FunctionsFunctions
Functions
 
visiblity and scope.pptx
visiblity and scope.pptxvisiblity and scope.pptx
visiblity and scope.pptx
 
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptxChapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
Chapter 13_m5JAVANOTESAPPLETS,INPUT.pptx
 

Recently uploaded

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
 
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
 
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
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
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
 
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
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
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
 

Recently uploaded (20)

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
 
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
 
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
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
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 ...
 
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
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
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
 
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...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
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
 

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