SlideShare a Scribd company logo
1 of 15
Storage Classes
in C++
Presented by : Jaspal Singh
What are Storage Classes
in C++ Programming ?
Types of Storage Classes
 Automatic
 External
 Static
 Register
 Mutable
Storage Class Keyword Lifetime Visibilty
Automatic auto Function Block Local
External extern Whole Program Global
Static static Whole Program Local
Register register Function Block Local
Mutable Mutable Class Local
Automatic Storage Class
Syntax of Automatic Storage :
datatype var_name1 [= value];
Or
auto datatype var_name1 [= value];
Example of Automatic Storage Class :
auto int x;
float y = 5.67;
External Storage Class
Syntax of External Storage Class :
extern datatype var_name1;
For example:
extern float var1;
Example of External Storage Class
File: sub.cpp
int test=100; // assigning value to test
void multiply(int n)
{
test=test*n;
}
File: main.cpp
#include<iostream>
#include "sub.cpp" // includes the content of sub.cpp
using namespace std;
extern int test; // declaring test
int main()
{
cout<<test<<endl;
multiply(5);
cout<<test<<endl;
return 0;
}
Output
100
500
Static Storage Class
Syntax of Static Storage Class
static datatype var_name1 [= value];
For example
static int x = 101;
static float sum;
Register Storage Class
Syntax of Register Storage Class
register datatype var_name1 [= value];
For example
register int id;
register char a;
Example : C++ program to create automatic,
static and register variables.
#include<iostream>
using namespace std;
int g; //global variable, initially holds 0
void test_function()
{
static int s; //static variable, initially
holds 0
register int r; //register variable
r=5;
s=s+r*2;
cout<<"Inside test_function"<<endl;
cout<<"g = "<<g<<endl;
cout<<"s = "<<s<<endl;
cout<<"r = "<<r<<endl;
}
int main()
{
int a; //automatic variable
g=25;
a=17;
test_function();
cout<<"Inside main"<<endl;
cout<<"a = "<<a<<endl;
cout<<"g = "<<g<<endl;
test_function();
return 0;
}
Output
Output
Inside test_function
g = 25
s = 10
r = 5
Inside main
a = 17
g = 25
Inside test_function
g = 25
s = 20
r = 5
Mutable Storage Class
Syntax for Mutable Storage Class Declaration
mutable datatype var_name1;
For example
mutable int x;
mutable char y;
Example of Mutable Storage Class
#include<iostream>
using namespace std;
class test
{
mutable int a;
int b;
public:
test(int x,int y)
{
a=x;
b=y;
}
void square_a() const
{
a=a*a;
}
void display() const
{
cout<<"a = "<<a<<endl;
cout<<"b = "<<b<<endl;
}
};
int main()
{
const test x(2,3);
cout<<"Initial value"<<endl;
x.display();
x.square_a();
cout<<"Final value"<<endl;
x.display();
return 0;
}
Output
Output
Initial value
a = 2
b = 3
Final value
a = 4
b = 3
Thank You!

More Related Content

What's hot (20)

Function in c
Function in cFunction in c
Function in c
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
File in C language
File in C languageFile in C language
File in C language
 
Data types in c++
Data types in c++ Data types in c++
Data types in c++
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
File in c
File in cFile in c
File in c
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
class and objects
class and objectsclass and objects
class and objects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 

Similar to Storage classes in c++

Similar to Storage classes in c++ (20)

Storage class
Storage classStorage class
Storage class
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
C++ theory
C++ theoryC++ theory
C++ theory
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
Storage class
Storage classStorage class
Storage class
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Storage class
Storage classStorage class
Storage class
 
from java to c
from java to cfrom java to c
from java to c
 
Storage classes
Storage classesStorage classes
Storage classes
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
11 lec 11 storage class
11 lec 11 storage class11 lec 11 storage class
11 lec 11 storage class
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 

Recently uploaded

OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrsaastr
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfakankshagupta7348026
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Krijn Poppe
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 

Recently uploaded (20)

OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
Motivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdfMotivation and Theory Maslow and Murray pdf
Motivation and Theory Maslow and Murray pdf
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
Presentation for the Strategic Dialogue on the Future of Agriculture, Brussel...
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 

Storage classes in c++

  • 2. What are Storage Classes in C++ Programming ?
  • 3. Types of Storage Classes  Automatic  External  Static  Register  Mutable
  • 4. Storage Class Keyword Lifetime Visibilty Automatic auto Function Block Local External extern Whole Program Global Static static Whole Program Local Register register Function Block Local Mutable Mutable Class Local
  • 5. Automatic Storage Class Syntax of Automatic Storage : datatype var_name1 [= value]; Or auto datatype var_name1 [= value]; Example of Automatic Storage Class : auto int x; float y = 5.67;
  • 6. External Storage Class Syntax of External Storage Class : extern datatype var_name1; For example: extern float var1;
  • 7. Example of External Storage Class File: sub.cpp int test=100; // assigning value to test void multiply(int n) { test=test*n; } File: main.cpp #include<iostream> #include "sub.cpp" // includes the content of sub.cpp using namespace std; extern int test; // declaring test int main() { cout<<test<<endl; multiply(5); cout<<test<<endl; return 0; } Output 100 500
  • 8. Static Storage Class Syntax of Static Storage Class static datatype var_name1 [= value]; For example static int x = 101; static float sum;
  • 9. Register Storage Class Syntax of Register Storage Class register datatype var_name1 [= value]; For example register int id; register char a;
  • 10. Example : C++ program to create automatic, static and register variables. #include<iostream> using namespace std; int g; //global variable, initially holds 0 void test_function() { static int s; //static variable, initially holds 0 register int r; //register variable r=5; s=s+r*2; cout<<"Inside test_function"<<endl; cout<<"g = "<<g<<endl; cout<<"s = "<<s<<endl; cout<<"r = "<<r<<endl; } int main() { int a; //automatic variable g=25; a=17; test_function(); cout<<"Inside main"<<endl; cout<<"a = "<<a<<endl; cout<<"g = "<<g<<endl; test_function(); return 0; }
  • 11. Output Output Inside test_function g = 25 s = 10 r = 5 Inside main a = 17 g = 25 Inside test_function g = 25 s = 20 r = 5
  • 12. Mutable Storage Class Syntax for Mutable Storage Class Declaration mutable datatype var_name1; For example mutable int x; mutable char y;
  • 13. Example of Mutable Storage Class #include<iostream> using namespace std; class test { mutable int a; int b; public: test(int x,int y) { a=x; b=y; } void square_a() const { a=a*a; } void display() const { cout<<"a = "<<a<<endl; cout<<"b = "<<b<<endl; } }; int main() { const test x(2,3); cout<<"Initial value"<<endl; x.display(); x.square_a(); cout<<"Final value"<<endl; x.display(); return 0; }
  • 14. Output Output Initial value a = 2 b = 3 Final value a = 4 b = 3