#include <iostream>
using namespace std;
class Demo
{
public:
int a = 1;
// static int b=2; //this gives error
static int b;
};
int Demo::b=2; //initialize the static variable of class
int main()
{
Demo d;
cout << "\n value of variable a: " << d.a << endl;
cout << "\n value of static variable b: " << Demo::b << endl;
}
OUTPUT:
using namespace std;
class Demo
{
public:
int a = 1;
// static int b=2; //this gives error
static int b;
};
int Demo::b=2; //initialize the static variable of class
int main()
{
Demo d;
cout << "\n value of variable a: " << d.a << endl;
cout << "\n value of static variable b: " << Demo::b << endl;
}
OUTPUT:
No comments:
Post a Comment