SlideShare a Scribd company logo
1 of 9
MADE BY :
MOHIT AGARWAL
161080107026
COMPUTER SEM - 4
CONTENTS
Static Data Member
Static Member Function
Example - Program
STATIC DATA MEMBERS
โ€ข We can define class members static using static keyword.
โ€ข A static member variable has certain special characteristics:
i. Shared by all objects of the class.
ii. Initialized to zero when the first object is created.
iii. Initialized outside the class.
A
B
A
B
OBJECT WITH TWO NORMAL
DATA MEMBERS
OBJECT WITH ONE NORMAL
AND ONE STATIC DATA MEMBER
STATIC MEMBER FUNCTIONS
โ€ข A static function can access only other static
members.
โ€ข It is called using class name and scope resolution
operator.
class name :: function name;
โ€ข It can not use this pointer.
EXAMPLE
#include <iostream.h>
#include <conio.h>
class test
{
int code;
static int count; //Static Member
public:
void set(void)
{
code=++count;
}
void show(void)
{
cout<<"Object number:"<<code<<endl;
}
static void showcount(void) //Static Function
{
cout<<"Count:"<<count<<endl;
}
};
int test::count; //Initializing Static Member
void main()
{
test t1,t2,t3;
clrscr();
t1.set();
test::showcount();
t2.set();
test::showcount(); //Accessing Static Function
t3.set();
test::showcount();
t1.show();
t2.show();
t3.show();
getch();
}
OUTPUT
Static Data Members and Member Functions

More Related Content

What's hot

Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
ย 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
ย 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
ย 

What's hot (20)

Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
ย 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
ย 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
ย 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
ย 
Method overloading
Method overloadingMethod overloading
Method overloading
ย 
Functions in c language
Functions in c language Functions in c language
Functions in c language
ย 
Types of Constructor in C++
Types of Constructor in C++Types of Constructor in C++
Types of Constructor in C++
ย 
File handling in c
File handling in cFile handling in c
File handling in c
ย 
Constructor and destructor
Constructor  and  destructor Constructor  and  destructor
Constructor and destructor
ย 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
ย 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
ย 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
ย 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
ย 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
ย 
This pointer
This pointerThis pointer
This pointer
ย 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
ย 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
ย 
Functions in c++
Functions in c++Functions in c++
Functions in c++
ย 
Templates in C++
Templates in C++Templates in C++
Templates in C++
ย 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
ย 

Similar to Static Data Members and Member Functions

Constructor
ConstructorConstructor
Constructor
abhay singh
ย 
static data member and member function .pptx
static data member and member function .pptxstatic data member and member function .pptx
static data member and member function .pptx
22X047SHRISANJAYM
ย 
Function class in c++
Function class in c++Function class in c++
Function class in c++
Kumar
ย 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-example
Deepak Singh
ย 

Similar to Static Data Members and Member Functions (20)

object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
ย 
Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2Object Oriented Programming using C++ - Part 2
Object Oriented Programming using C++ - Part 2
ย 
Lecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptxLecture-11 Friend Functions and inline functions.pptx
Lecture-11 Friend Functions and inline functions.pptx
ย 
class and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptxclass and object C++ language chapter 2.pptx
class and object C++ language chapter 2.pptx
ย 
Constructor
ConstructorConstructor
Constructor
ย 
C++.pptx
C++.pptxC++.pptx
C++.pptx
ย 
Object Oriented Programming Constructors & Destructors
Object Oriented Programming  Constructors &  DestructorsObject Oriented Programming  Constructors &  Destructors
Object Oriented Programming Constructors & Destructors
ย 
static data member and member function .pptx
static data member and member function .pptxstatic data member and member function .pptx
static data member and member function .pptx
ย 
Function class in c++
Function class in c++Function class in c++
Function class in c++
ย 
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptxstatic MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
static MEMBER IN OOPS PROGRAMING LANGUAGE.pptx
ย 
static members in object oriented program.pptx
static members in object oriented program.pptxstatic members in object oriented program.pptx
static members in object oriented program.pptx
ย 
Object and class presentation
Object and class presentationObject and class presentation
Object and class presentation
ย 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
ย 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
ย 
UNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptxUNIT3 on object oriented programming.pptx
UNIT3 on object oriented programming.pptx
ย 
concepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptxconcepts of object and classes in OOPS.pptx
concepts of object and classes in OOPS.pptx
ย 
Chapter22 static-class-member-example
Chapter22 static-class-member-exampleChapter22 static-class-member-example
Chapter22 static-class-member-example
ย 
Unit 2
Unit 2Unit 2
Unit 2
ย 
Object oriented programming 2
Object oriented programming 2Object oriented programming 2
Object oriented programming 2
ย 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
ย 

More from MOHIT AGARWAL (8)

Firewalls and packet filters
Firewalls and packet filtersFirewalls and packet filters
Firewalls and packet filters
ย 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 MicroprocessorCode Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
ย 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
ย 
Distance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing AlgorithmDistance Vector & Link state Routing Algorithm
Distance Vector & Link state Routing Algorithm
ย 
Modes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output OrganizationModes Of Transfer in Input/Output Organization
Modes Of Transfer in Input/Output Organization
ย 
Critical Section in Operating System
Critical Section in Operating SystemCritical Section in Operating System
Critical Section in Operating System
ย 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
ย 
Communication with Artificial intelligence
Communication with Artificial intelligenceCommunication with Artificial intelligence
Communication with Artificial intelligence
ย 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
ย 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
ย 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
ย 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
ย 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
ย 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
ย 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
ย 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
ย 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
ย 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
ย 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
ย 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
ย 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
ย 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
ย 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
ย 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
ย 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
ย 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
ย 

Static Data Members and Member Functions

  • 1. MADE BY : MOHIT AGARWAL 161080107026 COMPUTER SEM - 4
  • 2. CONTENTS Static Data Member Static Member Function Example - Program
  • 3. STATIC DATA MEMBERS โ€ข We can define class members static using static keyword. โ€ข A static member variable has certain special characteristics: i. Shared by all objects of the class. ii. Initialized to zero when the first object is created. iii. Initialized outside the class.
  • 4. A B A B OBJECT WITH TWO NORMAL DATA MEMBERS OBJECT WITH ONE NORMAL AND ONE STATIC DATA MEMBER
  • 5. STATIC MEMBER FUNCTIONS โ€ข A static function can access only other static members. โ€ข It is called using class name and scope resolution operator. class name :: function name; โ€ข It can not use this pointer.
  • 6. EXAMPLE #include <iostream.h> #include <conio.h> class test { int code; static int count; //Static Member public: void set(void) { code=++count; } void show(void) { cout<<"Object number:"<<code<<endl; } static void showcount(void) //Static Function { cout<<"Count:"<<count<<endl; } };
  • 7. int test::count; //Initializing Static Member void main() { test t1,t2,t3; clrscr(); t1.set(); test::showcount(); t2.set(); test::showcount(); //Accessing Static Function t3.set(); test::showcount(); t1.show(); t2.show(); t3.show(); getch(); }