Tuesday, October 23, 2012

Question 8: Predict the output.
    class DemoClass
    {
    public:
        DemoClass()
        {
            m_data = 20;
        }
        void print()
        {
            std::cout<<"\nData : "<<m_data;
        }
    private:
        int m_data;
    };

    int main()
    {
        DemoClass obj;
        obj.print();
        int* data = (int*)&obj;
        *data = 30;
        obj.print();
    }



    Options:

    a)     Data : 20
         Data : 30

    b)    Compilation Error

    c)     Run time crash.

    d)    None of the above.



    Answer: a

No comments:

Post a Comment