SlideShare a Scribd company logo
2
Most read
4
Most read
6
Most read
S.DHAKSHANAMOORTHY
S.SARAVANAN
M.VISHALVENKAT
N.DINESHKUMAR
K.R.SHAARUKESH
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.
EXAMPLE
//Static Member
#include <iostream>
using namespace std;
class Student {
public:
static int total;
Student() { total += 1; }
};
int Student::total = 0;
int main()
{
Student s1;
cout << "Number of students:" << s1.total << endl;
Student s2;
cout << "Number of students:" << s2.total << endl;
Student s3;
cout << "Number of students:" << s3.total << endl;
return 0;
}
OUTPUT
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
//Static Member
//Static Function
#include <iostream.h>
#include <conio.h>
class test
{
int code;
static int count;
public:
void set(void)
{
code=++count;
}
void show(void)
{
cout<<"Object number:"<<code<<endl;
}
static void showcount(void)
{
cout<<"Count:"<<count<<endl;
}
};
//Initializing Static Member
//Accessing Static Function
int test::count;
void main()
{
test t1,t2,t3;
clrscr();
t1.set();
test::showcount();
t2.set();
test::showcount();
t3.set();
test::showcount();
t1.show();
t2.show();
t3.show();
getch();
}
OUTPUT
EXAMPLE
#include <iostream>
using namespace std;
class Box
{
private:
static int length;
static int breadth;
static int height;
public:
static void print()
{
cout << "The value of the length is: " << length << endl;
cout << "The value of the breadth is: " << breadth << endl;
cout << "The value of the height is: " << height << endl;
}
};
int Box :: length = 10;
int Box :: breadth = 20;
int Box :: height = 30;
int main()
{
Box b;
cout << "Static member function is called through Object name: n" <<
endl;
b.print();
cout << "nStatic member function is called through Class name: n" <<
endl;
Box::print();
return 0;
}
OUTPUT
static data member and member function .pptx

More Related Content

PPTX
Static Data Members and Member Functions
PDF
Object Oriented Programming using C++ - Part 2
PPTX
C++ppt. Classs and object, class and object
PPTX
C++ Intro C++ Intro C++ Intro C++ Intro C++ Intro
PDF
chapter-7-classes-and-objects.pdf
PPSX
Object oriented programming 2
PPTX
object oriented programming-classes and objects.pptx
PPTX
3.Syntax.pptx for oops programing language
Static Data Members and Member Functions
Object Oriented Programming using C++ - Part 2
C++ppt. Classs and object, class and object
C++ Intro C++ Intro C++ Intro C++ Intro C++ Intro
chapter-7-classes-and-objects.pdf
Object oriented programming 2
object oriented programming-classes and objects.pptx
3.Syntax.pptx for oops programing language

Similar to static data member and member function .pptx (20)

PPTX
OOPs & C++ UNIT 3
PPT
Unit vi(dsc++)
PPT
classes & objects.ppt
PPTX
Static keyword.pptx
PPT
Classes, objects and methods
PPTX
OBJECT ORIENTED PROGRAMING IN C++
PDF
Object Oriented Programming Constructors & Destructors
PPTX
Lecture 2 (1)
PPTX
Presentation on class and object in Object Oriented programming.
PPTX
Lecture-11 Friend Functions and inline functions.pptx
PDF
Classes and objects
PDF
Object Oriented Programming using JAVA Notes
PPTX
Lecture_4_Static_variables_and_Methods.pptx
PPT
C++ Programming Course
PPT
Ccourse 140618093931-phpapp02
PPTX
C# classes objects
PPSX
Arre tari mano bhosko ka pikina tari ma no piko
PDF
Introduction to C++ Class & Objects. Book Notes
PPTX
Introduction to Fundamental of Class.pptx
PDF
Chapter22 static-class-member-example
OOPs & C++ UNIT 3
Unit vi(dsc++)
classes & objects.ppt
Static keyword.pptx
Classes, objects and methods
OBJECT ORIENTED PROGRAMING IN C++
Object Oriented Programming Constructors & Destructors
Lecture 2 (1)
Presentation on class and object in Object Oriented programming.
Lecture-11 Friend Functions and inline functions.pptx
Classes and objects
Object Oriented Programming using JAVA Notes
Lecture_4_Static_variables_and_Methods.pptx
C++ Programming Course
Ccourse 140618093931-phpapp02
C# classes objects
Arre tari mano bhosko ka pikina tari ma no piko
Introduction to C++ Class & Objects. Book Notes
Introduction to Fundamental of Class.pptx
Chapter22 static-class-member-example
Ad

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Microbial disease of the cardiovascular and lymphatic systems
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
VCE English Exam - Section C Student Revision Booklet
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Module 4: Burden of Disease Tutorial Slides S2 2025
O5-L3 Freight Transport Ops (International) V1.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
TR - Agricultural Crops Production NC III.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Ad

static data member and member function .pptx

  • 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. EXAMPLE //Static Member #include <iostream> using namespace std; class Student { public: static int total; Student() { total += 1; } }; int Student::total = 0; int main() { Student s1; cout << "Number of students:" << s1.total << endl; Student s2; cout << "Number of students:" << s2.total << endl; Student s3; cout << "Number of students:" << s3.total << endl; return 0; }
  • 6. 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.
  • 7. EXAMPLE //Static Member //Static Function #include <iostream.h> #include <conio.h> class test { int code; static int count; public: void set(void) { code=++count; } void show(void) { cout<<"Object number:"<<code<<endl; } static void showcount(void) { cout<<"Count:"<<count<<endl; } };
  • 8. //Initializing Static Member //Accessing Static Function int test::count; void main() { test t1,t2,t3; clrscr(); t1.set(); test::showcount(); t2.set(); test::showcount(); t3.set(); test::showcount(); t1.show(); t2.show(); t3.show(); getch(); }
  • 10. EXAMPLE #include <iostream> using namespace std; class Box { private: static int length; static int breadth; static int height; public: static void print() { cout << "The value of the length is: " << length << endl; cout << "The value of the breadth is: " << breadth << endl; cout << "The value of the height is: " << height << endl; } }; int Box :: length = 10; int Box :: breadth = 20; int Box :: height = 30;
  • 11. int main() { Box b; cout << "Static member function is called through Object name: n" << endl; b.print(); cout << "nStatic member function is called through Class name: n" << endl; Box::print(); return 0; }