Write a program which gives the example of static function in C++?
#include<iostream.h>
#include<conio.h>
class
a
{
static
int c;
public:
static
void a1()
{
c++;
}
static
void a2()
{
cout<<"\nafter
increment c is\n"<<c;
}
};
int
a::c=5;
void
main()
{
clrscr();
class
a obj;
a::a2();
a::a1();
a::a2();
getch();
}
OUTPUT:-
after
increment c is
5
after
increment c is
6
Comments
Post a Comment