Hi,
I've confusion with static member variable in c++ class.
Please have a look on following code.
class test
{
public:
static int i;
float j;
};
int test::i = 0;
int main()
{
test *t = new test;
test::i = 100;
cout << "test::i = " << test::i << endl;
t->j = 10.67;
cout << "t->j = " << t->j << endl;
delete t;
t = NULL;
t->i = 200;
cout << "t->i = " << t->i << endl;
return 0;
}
In above code, i've delete class pointer, t and assigned it to NULL;
and on that i'm accessing static member variable (t->i). It is working fine.
My question is why it should not crash, as i'm accessing member variable on null.
Please help.
Thanks & regards,
Amar