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

PDF
Object oriented programming c++
PPT
C by balaguruswami - e.balagurusamy
PPTX
Data Type Conversion in C++
PPTX
Basic Data Types in C++
PDF
Constructors and Destructors
PPTX
Function in C program
PPT
Lecture 5 - Structured Programming Language
PDF
Manipulators
Object oriented programming c++
C by balaguruswami - e.balagurusamy
Data Type Conversion in C++
Basic Data Types in C++
Constructors and Destructors
Function in C program
Lecture 5 - Structured Programming Language
Manipulators

What's hot (20)

PPTX
Constructors in C++
PDF
Operator overloading C++
PPTX
Function C programming
PPTX
Union in C programming
PPTX
Dynamic memory allocation
PPT
Formatted input and output
PPTX
PPT
How to execute a C program
PPTX
Introduction to C++
PPTX
Storage classes in c language
PDF
Operators in c programming
PPT
Oops ppt
PPTX
C++ Overview PPT
PPT
Class and object in C++
PPTX
Operators and expressions
PDF
SPL 9 | Scope of Variables in C
PPTX
c++ programming Unit 2 basic structure of a c++ program
PPTX
data types in C programming
PDF
c++ lab manual
PPTX
Call by value
Constructors in C++
Operator overloading C++
Function C programming
Union in C programming
Dynamic memory allocation
Formatted input and output
How to execute a C program
Introduction to C++
Storage classes in c language
Operators in c programming
Oops ppt
C++ Overview PPT
Class and object in C++
Operators and expressions
SPL 9 | Scope of Variables in C
c++ programming Unit 2 basic structure of a c++ program
data types in C programming
c++ lab manual
Call by value
Ad

Similar to Storage classes in c++ (20)

PPT
STORAGE CLASSES
PPT
Storage classes
DOC
What is storage class
PPT
storage class
PDF
Storage class
PDF
C storage classes
PPTX
Storage class in c
PPT
Lecture 13 - Storage Classes
DOCX
Storage class
PPTX
Storage classes in C
PPTX
Storage classes
PDF
Storage classes arrays & functions in C Language
PPTX
Storage Classes and Functions
PPTX
Storage class
PPTX
Storage Class
PPTX
STORAGE CLASS.pptx
PDF
variablesfinal-170820055428 data type results
PPTX
Variables in C++, data types in c++
PPTX
Storage class in C Language
PDF
Storage class
STORAGE CLASSES
Storage classes
What is storage class
storage class
Storage class
C storage classes
Storage class in c
Lecture 13 - Storage Classes
Storage class
Storage classes in C
Storage classes
Storage classes arrays & functions in C Language
Storage Classes and Functions
Storage class
Storage Class
STORAGE CLASS.pptx
variablesfinal-170820055428 data type results
Variables in C++, data types in c++
Storage class in C Language
Storage class
Ad

Recently uploaded (20)

PDF
Unnecessary information is required for the
PPTX
CASEWORK Power Point Presentation - pointers
PPTX
3RD-Q 2022_EMPLOYEE RELATION - Copy.pptx
PPTX
Religious Thinkers Presentationof subcontinent
PDF
IKS PPT.....................................
PPTX
ANICK 6 BIRTHDAY....................................................
PPTX
2025-08-17 Joseph 03 (shared slides).pptx
PPTX
Lesson 1 (Digital Media) - Multimedia.pptx
PPTX
Unit 8#Concept of teaching and learning.pptx
PPTX
Bob Difficult Questions 08 17 2025.pptx
PDF
5_tips_to_become_a_Presentation_Jedi_@itseugenec.pdf
PPTX
Kompem Part Untuk MK Komunikasi Pembangunan 5.pptx
PPTX
TG Hospitality workshop Vietnam (1).pptx
PPTX
PurpoaiveCommunication for students 02.pptx
PDF
PM Narendra Modi's speech from Red Fort on 79th Independence Day.pdf
DOC
EVC毕业证学历认证,北密歇根大学毕业证留学硕士毕业证
PPTX
Phrases and phrasal verb for a small step.
PDF
_Nature and dynamics of communities and community development .pdf
PPTX
Public Speaking Is Easy . Start Now . It's now or never.
PPTX
WEB_DEVELOPMENTGJMFGHJMGJMFJM FGJMFGHMNF
Unnecessary information is required for the
CASEWORK Power Point Presentation - pointers
3RD-Q 2022_EMPLOYEE RELATION - Copy.pptx
Religious Thinkers Presentationof subcontinent
IKS PPT.....................................
ANICK 6 BIRTHDAY....................................................
2025-08-17 Joseph 03 (shared slides).pptx
Lesson 1 (Digital Media) - Multimedia.pptx
Unit 8#Concept of teaching and learning.pptx
Bob Difficult Questions 08 17 2025.pptx
5_tips_to_become_a_Presentation_Jedi_@itseugenec.pdf
Kompem Part Untuk MK Komunikasi Pembangunan 5.pptx
TG Hospitality workshop Vietnam (1).pptx
PurpoaiveCommunication for students 02.pptx
PM Narendra Modi's speech from Red Fort on 79th Independence Day.pdf
EVC毕业证学历认证,北密歇根大学毕业证留学硕士毕业证
Phrases and phrasal verb for a small step.
_Nature and dynamics of communities and community development .pdf
Public Speaking Is Easy . Start Now . It's now or never.
WEB_DEVELOPMENTGJMFGHJMGJMFJM FGJMFGHMNF

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