Write a program which gives the example of static variable in c++ ?



#include<iostream.h>
#include<conio.h>
class a
{
static int c;
public:
void a1()
{
c++;
}
void a2()
{
cout<<"\nafter increment c is\n"<<c;
}
};
int a::c=5;
void main()
{
clrscr();
class a obj;
obj.a2();
obj.a1();
obj.a2();
getch();
}










OUTPUT:-

after increment c is
5
after increment c is
6

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart