Question 4: Predict the output.
class DemoClass
{
public:
void display()
{
std::cout<<"Display Function.";
}
private:
};
int main()
{
DemoClass* obj = 0;
obj->display();
}
Options:
a) Compilation Error.
b) Run time crash.
c) Display Function.
d) None of the above.
Answer: c
Here as display is not using 'this' pointer to refer to any data member the call is not giving a seg fault . Still de-refferencing a NULL pointer is undefined .
ReplyDeleteNote: The call may succeed but still the behavior is undefined according to C++ standards .