Why the below program is not producing a runtime error!!
#include <iostream>
using namespace std;
class temp
{
public:
void func(){cout<<"it works"<<endl;}
};
int main()
{
temp* ptr = NULL;
ptr->func();
return 0;
}
this code prints "it works" why?? ptr is accessing NULL memory it should crash.
if the explanation is that class has no member variables , then i tried the following code and it also works why??
#include <iostream>
using namespace std;
class temp
{
int i;
public:
void func(){cout<<"it works"<<endl;}
};
int main()
{
temp* ptr = NULL;
ptr->func();
return 0;
}