C++ Simple Program of Static Data Member

      No Comments on C++ Simple Program of Static Data Member

Program of Static Data Member

C++ Simple Program of Static Data Member.Static member are initilized to zero when object of its class is created.Also only one copy of that member is created for the entire class.It is only visible within the class.

Program

#include<iostream.h>
#include<conio.h>
class scan
{     public:
    static int x;
	int y;
  scan()
   {

     x++;
     y++;
   }
   void display()
     {
      cout<<"Value of x = "<<x<<endl;
      cout<<"Value of y = "<<y<<endl;
     }
};
int scan::x=0;
void main()
{
 clrscr();
 scan s1,s2,s3;
 s1.display();
 s2.display();
 s2.display();
 getch();
}

OUTPUT:-

Static Data Member


Comment below if you are facing any problem


Also read

C++ Program to add two numbers by defining function Outside the class
C++ program to print 3×3 matrix using class
C++ program to print alternate elements from an array


Summary
C++ Simple Program of Static Data Member
Article Name
C++ Simple Program of Static Data Member
Description
Static member are initilized to zero when object of its class is created.Also only one copy of that member is created for the entire class.It is only visible within the class.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *