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
Post a Comment