Static variable:
Static variable are those variable whose memory is shareable.
or,
Static variable are declared once in entire life time of the program.
Synatx:
static data_type variable_name;
program:
#include < iostream>
using namespace std;
//class declared
class Myclass
{
public:
void function()
{
//line 1
static int a=10;
cout<< a<< endl;
a=a+5;
}
};
int main()
{
Myclass obj;
obj.function();
obj.function();
return 0;
}
10
15