Tuesday, October 23, 2012

Question 1: Predict the output

    #include<iostream>
    #include<conio.h>

    class DemoClass
    {
    public:
        DemoClass(int value);
        void printValues();
    private:
        int m_data;
        int m_otherData;
    };

    DemoClass::DemoClass(int value):m_otherData(value), m_data(m_otherData)
    {
    }

    void DemoClass::printValues()
    {
        std::cout<<"Data: "<<m_data<<"\nOther Data : "<<m_otherData;
    }

    int main()
    {
        DemoClass obj(20);
        obj.printValues();
        getch();
    }


    Options:
                a)     Data : 20
               Other Data: 20
          b)    Data : Garbage Value
               Other Data: Garbage Value

          c)     Data : Garbage Value
               Other Data: 20

          d)    None of the above.

    Answer: c

No comments:

Post a Comment