SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Storage class in C
INTRODUCTION
• Not only variables have data types but also a storage class..
• Where the variable would be stored.
• Default initial value if not specifically assigned.
• Scope i.e in which function the value would be available.
• How log would the variable exist.
CLASSIFICATION
• Automatic storage class
• Register storage class
• Static storage class
• External storage class
AUTOMATIC STORAGE CLASS
Are declare inside a function in which they are to be utilized.
Are declared using a keyword auto.
eg. auto int number;
Are created when the function is called and destroyed
automatically when the function is exited.
This variable are therefore private(local) to the function in which
they are declared.
Variables declared inside a function without storage class
specification is, by default, an automatic variable.
EXAMPLE PROGRAM
int main()
{ int m=1000;
function2();
printf(“%d n”,m);
}
function1()
{
int m = 10;
printf(“%dn”,m);
}
function2()
{ int m = 100;
function1();
printf(“%dn”,m);
}
Output
10
100
1000
EXTERNAL STORAGE CLASS
• These variables are declared outside any function.
• These variables are active and alive throughout the entire program.
• Also known as global variables and default value is zero.
• Unlike local variables they are accessed by any function in the program.
• In case local variable and global variable have the same name, the local variable will
have precedence over the global one.
• Sometimes the keyword extern used to declare these variable.
• It is visible only from the point of declaration to the end of the program.
EXTERNAL VARIABLE (EXAMPLES)
int n;
main()
{ increment();
increment();
decrement();
}
increment()
{n=n+1;
Printf(“ inc value %d”,n);
}
decrement()
{n=n-1
Printf(“ inc value %d”,n);
}
int x=10;
main()
{int x=20;
printf(“n %d”,x);
display();
}
display()
{
printf(“n %d”,x);
}
The variable n is available for
use in all three function
When the function references the
variable count, it will be referencing
only its local variable, not the global
one.
STATIC STORAGE CLASS
• The value of static variables persists until the end of the program.
• It is declared using the keyword static like
static int x;
static float y;
• It may be of external or internal type depending on the place of there
declaration.
• Static variables are initialized only once, when the program is compiled.
EXAMPLE OF STATIC
• Internal static variable can be used to count the number of calls made to function. eg.
int main()
{
int I;
for(i =1; i<=3; i++)
stat();
}
void stat()
{
static int x=0;
x = x+1;
printf(“x = %dn”,x);
}
Output
x=1
x=2
x=3
REGISTER STORAGE CLASS
These variables are stored in one of the machine’s register and are declared using
register keyword.
eg. register int count;
Since register access are much faster than a memory access keeping frequently
accessed variables in the register lead to faster execution of program.
Since only few variable can be placed in the register, it is important to carefully select
the variables for this purpose. However, C will automatically convert register variables
into nonregister variables once the limit is reached.
Don’t try to declare a global variable as register. Because the register will be occupied
during the lifetime of the program.
Storage class in c

Weitere ähnliche Inhalte

Was ist angesagt?

Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
Kamal Acharya
 

Was ist angesagt? (20)

Functions in C
Functions in CFunctions in C
Functions in C
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Function in C program
Function in C programFunction in C program
Function in C program
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
C functions
C functionsC functions
C functions
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Storage classes
Storage classesStorage classes
Storage classes
 
Function in C
Function in CFunction in C
Function in C
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
STORAGE CLASSES
STORAGE CLASSESSTORAGE CLASSES
STORAGE CLASSES
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Function
FunctionFunction
Function
 

Andere mochten auch (10)

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
C and its errors
C and its errorsC and its errors
C and its errors
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Design Pattern Libraries
Design Pattern LibrariesDesign Pattern Libraries
Design Pattern Libraries
 
Loops in C
Loops in CLoops in C
Loops in C
 
Loops c++
Loops c++Loops c++
Loops c++
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 

Ähnlich wie Storage class in c

S torage class in C
S torage class in CS torage class in C
S torage class in C
kash95
 
What is storage class
What is storage classWhat is storage class
What is storage class
Isha Aggarwal
 
11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class
웅식 전
 

Ähnlich wie Storage class in c (20)

S torage class in C
S torage class in CS torage class in C
S torage class in C
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
C functions list
C functions listC functions list
C functions list
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Storage class
Storage classStorage class
Storage class
 
Storage class
Storage classStorage class
Storage class
 
function in c
function in cfunction in c
function in c
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Storage classes
Storage classesStorage classes
Storage classes
 
Lecture6
Lecture6Lecture6
Lecture6
 
Unit iii
Unit iiiUnit iii
Unit iii
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Storage class
Storage classStorage class
Storage class
 
Interesting facts on c
Interesting facts on cInteresting facts on c
Interesting facts on c
 
5.program structure
5.program structure5.program structure
5.program structure
 
Unit 8
Unit 8Unit 8
Unit 8
 
11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class11 2. variable-scope rule,-storage_class
11 2. variable-scope rule,-storage_class
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 

Kürzlich hochgeladen

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Kürzlich hochgeladen (20)

Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 

Storage class in c

  • 2. INTRODUCTION • Not only variables have data types but also a storage class.. • Where the variable would be stored. • Default initial value if not specifically assigned. • Scope i.e in which function the value would be available. • How log would the variable exist.
  • 3. CLASSIFICATION • Automatic storage class • Register storage class • Static storage class • External storage class
  • 4. AUTOMATIC STORAGE CLASS Are declare inside a function in which they are to be utilized. Are declared using a keyword auto. eg. auto int number; Are created when the function is called and destroyed automatically when the function is exited. This variable are therefore private(local) to the function in which they are declared. Variables declared inside a function without storage class specification is, by default, an automatic variable.
  • 5. EXAMPLE PROGRAM int main() { int m=1000; function2(); printf(“%d n”,m); } function1() { int m = 10; printf(“%dn”,m); } function2() { int m = 100; function1(); printf(“%dn”,m); } Output 10 100 1000
  • 6. EXTERNAL STORAGE CLASS • These variables are declared outside any function. • These variables are active and alive throughout the entire program. • Also known as global variables and default value is zero. • Unlike local variables they are accessed by any function in the program. • In case local variable and global variable have the same name, the local variable will have precedence over the global one. • Sometimes the keyword extern used to declare these variable. • It is visible only from the point of declaration to the end of the program.
  • 7. EXTERNAL VARIABLE (EXAMPLES) int n; main() { increment(); increment(); decrement(); } increment() {n=n+1; Printf(“ inc value %d”,n); } decrement() {n=n-1 Printf(“ inc value %d”,n); } int x=10; main() {int x=20; printf(“n %d”,x); display(); } display() { printf(“n %d”,x); } The variable n is available for use in all three function When the function references the variable count, it will be referencing only its local variable, not the global one.
  • 8. STATIC STORAGE CLASS • The value of static variables persists until the end of the program. • It is declared using the keyword static like static int x; static float y; • It may be of external or internal type depending on the place of there declaration. • Static variables are initialized only once, when the program is compiled.
  • 9. EXAMPLE OF STATIC • Internal static variable can be used to count the number of calls made to function. eg. int main() { int I; for(i =1; i<=3; i++) stat(); } void stat() { static int x=0; x = x+1; printf(“x = %dn”,x); } Output x=1 x=2 x=3
  • 10. REGISTER STORAGE CLASS These variables are stored in one of the machine’s register and are declared using register keyword. eg. register int count; Since register access are much faster than a memory access keeping frequently accessed variables in the register lead to faster execution of program. Since only few variable can be placed in the register, it is important to carefully select the variables for this purpose. However, C will automatically convert register variables into nonregister variables once the limit is reached. Don’t try to declare a global variable as register. Because the register will be occupied during the lifetime of the program.