SlideShare a Scribd company logo
Storage Classes in C
Storage Classes are used to describe the features of a variable/function. These features
basically include the scope, visibility and life-time which help us to trace the existence of a
particular variable during the runtime of a program.
A storage class in C is used to describe the following things:
•The variable scope.
•The location where the variable will be stored.
•The initialized value of a variable.
•A lifetime of a variable.
•Who can access a variable?
Thus a storage class is used to represent the information about a variable.
NOTE: A variable is not only associated with a data type, its value but also
a storage class.
C language uses 4 storage classes, namely:
Storage class Purpose
auto It is a default storage class.
extern It is a global variable.
static It is a local variable which is capable
of returning a value even when
control is transferred to the function
call.
register It is a variable which is stored inside
a Register.
AUTO
EXTERN
STATIC
REGISTER
This is the default storage class for all the variables
declared inside a function or a block. Hence, the
keyword auto is rarely used while writing programs
in C language. Auto variables can be only
accessed within the block/function they have been
declared and not outside them (which defines their
scope). Of course, these can be accessed within
nested blocks within the parent block/function in
which the auto variable was declared. However,
they can be accessed outside their scope as well
using the concept of pointers given here by
pointing to the very exact memory location where
the variables resides. They are assigned a garbage
value by default whenever they are declared.
AUTO
EXTERN
STATIC
REGISTER
Extern storage class simply tells us that the
variable is defined elsewhere and not within
the same block where it is used. Basically,
the value is assigned to it in a different
block and this can be overwritten/changed
in a different block as well. So an extern
variable is nothing but a global variable
initialized with a legal value where it is
declared in order to be used elsewhere. It
can be accessed within any function/block.
Also, a normal global variable can be made
extern as well by placing the ‘extern’
keyword before its declaration/definition in
any function/block. This basically signifies
that we are not initializing a new variable
but instead we are using/accessing the
global variable only.
AUTO
EXTERN
STATIC
REGISTER
This storage class is used to declare static
variables which are popularly used while
writing programs in C language. Static
variables have a property of preserving
their value even after they are out of their
scope! Hence, static variables preserve the
value of their last use in their scope. So we
can say that they are initialized only once
and exist till the termination of the program.
Thus, no new memory is allocated because
they are not re-declared. Their scope is
local to the function to which they were
defined. Global static variables can be
accessed anywhere in the program. By
default, they are assigned the value 0 by
the compiler.
EXTERN
STATIC
REGISTER
AUTO This storage class declares register variables
which have the same functionality as that of the
auto variables. The only difference is that the
compiler tries to store these variables in the
register of the microprocessor if a free register is
available. This makes the use of register variables
to be much faster than that of the variables stored
in the memory during the runtime of the program.
If a free register is not available, these are then
stored in the memory only. Usually few variables
which are to be accessed very frequently in a
program are declared with the register keyword
which improves the running time of the program.
An important and interesting point to be noted
here is that we cannot obtain the address of a
register variable using pointers.
EXAMPLES OF
THE STORAGE
CLASSES
AUTO
EXTERN
STATIC
REGISTER
1.#include <stdio.h>
2.int main()
3.{
4.int a; //auto
5.char b;
6.float c;
7.printf("%d %c %f",a,b,c); // printing initial
default value of automatic variables a, b, and c.
8.return 0;
9.}
Output:
garbage garbage garbage
AUTO
EXTERN
STATIC
REGISTER
1.#include <stdio.h>
2.int a;
3.int main()
4.{
5.extern int a; // variable a is defined
globally, the memory will not be allocated
to a
6.printf("%d",a);
7.}
Output:
0
AUTO
EXTERN
STATIC
REGISTER
1.#include<stdio.h>
2.void sum()
3.{
4.static int a = 10;
5.static int b = 24;
6.printf("%d %d n",a,b);
7.a++;
8.b++;
9.}
10.void main()
11.{
12.int i;
13.for(i = 0; i< 3; i++)
14.{
15.sum(); // The static variables holds their value between
multiple function calls.
16.}
17.}
Output:
10 24
11 25
12 26
AUTO
EXTERN
STATIC
REGISTER
1.#include <stdio.h>
2.int main()
3.{
4.register int a; // variable a is
allocated memory in the CPU
register. The initial default value
of a is 0.
5.printf("%d",a);
6.}
Output:
0
Created By :- Mr. UTTAM VERMA
M.C.A. 1ST SEMESTER
M.D.S.U (AJMER)

More Related Content

What's hot

Storage class in c
Storage class in cStorage class in c
Storage class in c
kash95
 
Storage class
Storage classStorage class
Storage class
Joy Forerver
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
Self employed
 
Storage classes
Storage classesStorage classes
Storage classes
Leela Koneru
 
C functions
C functionsC functions
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 
Function lecture
Function lectureFunction lecture
Function lecture
DIT University, Dehradun
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
Function in c
Function in cFunction in c
Function in c
savitamhaske
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
Function overloading
Function overloadingFunction overloading
Function overloading
Selvin Josy Bai Somu
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
inline function
inline function inline function
inline function
imran khan
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 

What's hot (20)

Function
FunctionFunction
Function
 
Storage class in c
Storage class in cStorage class in c
Storage class in c
 
Storage class
Storage classStorage class
Storage class
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Storage classes
Storage classesStorage classes
Storage classes
 
C functions
C functionsC functions
C functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Function in c
Function in cFunction in c
Function in c
 
Function lecture
Function lectureFunction lecture
Function lecture
 
Types of function call
Types of function callTypes of function call
Types of function call
 
Function in c
Function in cFunction in c
Function in c
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
inline function
inline function inline function
inline function
 
C++ Function
C++ FunctionC++ Function
C++ Function
 

Similar to Storage classes

Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
Reddhi Basu
 
Storage classes
Storage classesStorage classes
Storage classes
priyanka jain
 
Storage classes
Storage classesStorage classes
Storage classes
Praveen M Jigajinni
 
Storage Class Specifiers
Storage Class SpecifiersStorage Class Specifiers
Storage Class Specifiers
Reddhi Basu
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
Tanmay Modi
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
tanmaymodi4
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
Appili Vamsi Krishna
 
STORAGE CLASS.pptx
STORAGE CLASS.pptxSTORAGE CLASS.pptx
STORAGE CLASS.pptx
BU210535JeevanKishor
 
Terms and Definitions.pdf
Terms and Definitions.pdfTerms and Definitions.pdf
Terms and Definitions.pdf
SheikhAbrarAhmad
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
C storage class
C storage classC storage class
5.program structure
5.program structure5.program structure
5.program structure
Shankar Gangaju
 
What is storage class
What is storage classWhat is storage class
What is storage classIsha Aggarwal
 
Storage class
Storage classStorage class
Storage class
Kalaikumar Thangapandi
 
Understanding Storage Classes in C.pdf
Understanding Storage Classes in C.pdfUnderstanding Storage Classes in C.pdf
Understanding Storage Classes in C.pdf
SumanaDotNetTricks
 
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
 
Storage classes
Storage classesStorage classes
Storage classes
Puneet Rajput
 
Types of storage class specifiers in c programming
Types of storage class specifiers in c programmingTypes of storage class specifiers in c programming
Types of storage class specifiers in c programming
Appili Vamsi Krishna
 

Similar to Storage classes (20)

Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage Class Specifiers
Storage Class SpecifiersStorage Class Specifiers
Storage Class Specifiers
 
Storage classes
Storage classesStorage classes
Storage classes
 
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
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
STORAGE CLASS.pptx
STORAGE CLASS.pptxSTORAGE CLASS.pptx
STORAGE CLASS.pptx
 
Terms and Definitions.pdf
Terms and Definitions.pdfTerms and Definitions.pdf
Terms and Definitions.pdf
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
C storage class
C storage classC storage class
C storage class
 
5.program structure
5.program structure5.program structure
5.program structure
 
What is storage class
What is storage classWhat is storage class
What is storage class
 
Storage class
Storage classStorage class
Storage class
 
Understanding Storage Classes in C.pdf
Understanding Storage Classes in C.pdfUnderstanding Storage Classes in C.pdf
Understanding Storage Classes in C.pdf
 
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
 
Types of storage class specifiers in c programming
Types of storage class specifiers in c programmingTypes of storage class specifiers in c programming
Types of storage class specifiers in c programming
 

Recently uploaded

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 

Recently uploaded (20)

20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 

Storage classes

  • 1. Storage Classes in C Storage Classes are used to describe the features of a variable/function. These features basically include the scope, visibility and life-time which help us to trace the existence of a particular variable during the runtime of a program. A storage class in C is used to describe the following things: •The variable scope. •The location where the variable will be stored. •The initialized value of a variable. •A lifetime of a variable. •Who can access a variable? Thus a storage class is used to represent the information about a variable. NOTE: A variable is not only associated with a data type, its value but also a storage class.
  • 2. C language uses 4 storage classes, namely: Storage class Purpose auto It is a default storage class. extern It is a global variable. static It is a local variable which is capable of returning a value even when control is transferred to the function call. register It is a variable which is stored inside a Register.
  • 3. AUTO EXTERN STATIC REGISTER This is the default storage class for all the variables declared inside a function or a block. Hence, the keyword auto is rarely used while writing programs in C language. Auto variables can be only accessed within the block/function they have been declared and not outside them (which defines their scope). Of course, these can be accessed within nested blocks within the parent block/function in which the auto variable was declared. However, they can be accessed outside their scope as well using the concept of pointers given here by pointing to the very exact memory location where the variables resides. They are assigned a garbage value by default whenever they are declared.
  • 4. AUTO EXTERN STATIC REGISTER Extern storage class simply tells us that the variable is defined elsewhere and not within the same block where it is used. Basically, the value is assigned to it in a different block and this can be overwritten/changed in a different block as well. So an extern variable is nothing but a global variable initialized with a legal value where it is declared in order to be used elsewhere. It can be accessed within any function/block. Also, a normal global variable can be made extern as well by placing the ‘extern’ keyword before its declaration/definition in any function/block. This basically signifies that we are not initializing a new variable but instead we are using/accessing the global variable only.
  • 5. AUTO EXTERN STATIC REGISTER This storage class is used to declare static variables which are popularly used while writing programs in C language. Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve the value of their last use in their scope. So we can say that they are initialized only once and exist till the termination of the program. Thus, no new memory is allocated because they are not re-declared. Their scope is local to the function to which they were defined. Global static variables can be accessed anywhere in the program. By default, they are assigned the value 0 by the compiler.
  • 6. EXTERN STATIC REGISTER AUTO This storage class declares register variables which have the same functionality as that of the auto variables. The only difference is that the compiler tries to store these variables in the register of the microprocessor if a free register is available. This makes the use of register variables to be much faster than that of the variables stored in the memory during the runtime of the program. If a free register is not available, these are then stored in the memory only. Usually few variables which are to be accessed very frequently in a program are declared with the register keyword which improves the running time of the program. An important and interesting point to be noted here is that we cannot obtain the address of a register variable using pointers.
  • 8. AUTO EXTERN STATIC REGISTER 1.#include <stdio.h> 2.int main() 3.{ 4.int a; //auto 5.char b; 6.float c; 7.printf("%d %c %f",a,b,c); // printing initial default value of automatic variables a, b, and c. 8.return 0; 9.} Output: garbage garbage garbage
  • 9. AUTO EXTERN STATIC REGISTER 1.#include <stdio.h> 2.int a; 3.int main() 4.{ 5.extern int a; // variable a is defined globally, the memory will not be allocated to a 6.printf("%d",a); 7.} Output: 0
  • 10. AUTO EXTERN STATIC REGISTER 1.#include<stdio.h> 2.void sum() 3.{ 4.static int a = 10; 5.static int b = 24; 6.printf("%d %d n",a,b); 7.a++; 8.b++; 9.} 10.void main() 11.{ 12.int i; 13.for(i = 0; i< 3; i++) 14.{ 15.sum(); // The static variables holds their value between multiple function calls. 16.} 17.} Output: 10 24 11 25 12 26
  • 11. AUTO EXTERN STATIC REGISTER 1.#include <stdio.h> 2.int main() 3.{ 4.register int a; // variable a is allocated memory in the CPU register. The initial default value of a is 0. 5.printf("%d",a); 6.} Output: 0
  • 12. Created By :- Mr. UTTAM VERMA M.C.A. 1ST SEMESTER M.D.S.U (AJMER)