Tuesday, October 23, 2012

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

1 comment:

  1. 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 .

    Note: The call may succeed but still the behavior is undefined according to C++ standards .

    ReplyDelete