adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class sample1 
    {
        float i, j;
    };
    class sample2 
    {
        int x, y;
        public:
        sample2 (int a, int b) 
        {
             x = a; 
             y = b;
        }
        int result() 
        { 
             return x + y;
         }
    };
    int main () 
    {
        sample1 d;
        sample2 * padd;
        padd = (sample2*) &d;
        cout < result();
        return 0;
    }

a.

20

b.

runtime error

c.

random number

d.

runtime error or random number

Answer: (d).runtime error or random number

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?