I do not understand how the below piece of code yields the given output.
#include <iostream>
using namespace std;
class MyClass
{
public:
void doSomething()
{
cout<<"Inside doSomething"<<endl;
}
};
int main()
{
MyClass obj;
MyClass *ptr=&obj;
ptr->doSomething();
ptr=NULL;
ptr->doSomething();
}
Output
Inside doSomething
Inside doSomething
I executed a function with a null pointer and it actually calls the function. Retrieving the address stored in the ptr using cout of ptr shows that ptr is set to 0 after the statement ptr=NULL; .But it still calls doSomething().What is actually happening inside ?