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

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)

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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
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
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 

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(); }