Make Your Search Easy ! :) Use me

Friday, February 17, 2017

Static Variable & Function

Program to demonstrate the use of Static variable and function :-

#include<iostream.h>
#include<conio.h>


class xyz
{
int a;
static int count;
public:
xyz()
{
count++;
}
void get()
{
cout<<"\nEnter value of A (just to check the functioning of the class) :  ";//just to check the functionality of the class
cin>>a;
}
void show()
{
cout<<"\nValue of A = "<<a<<" (Class Object is Working Normally)";//just to check the functionality of the class
}
static void show_count()
{
cout<<"\n\nValue of Count is i.e. No. of Objects Created:  "<<count;
}
};


int xyz::count=0;


void main()
{
xyz x,y,z;
x.get();
x.show();
xyz::show_count();
getch();
}

No comments:

Post a Comment