Exercise: References

Questions for: References

Which of the following statement is correct about the program given below?
#include<iostream.h> 
class ExamAdept
{
    int x, y; 
    public:
    ExamAdept(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    ExamAdept operator +(ExamAdept z)
    {
        ExamAdept objTemp;
        objTemp.x = x + z.x;
        objTemp.y = y + z.y;
        return objTemp; 
    }
};
int main()
{
    ExamAdept objBix1(90, 80); 
    ExamAdept objBix2(10, 20); 
    ExamAdept objSum; 
    ExamAdept &objRef = objSum; 
    objRef = objBix1 + objBix2; 
    objRef.Display(); 
    return 0; 
}
A:
It will result in a runtime error.
B:
It will result in a compile time error.
C:
The program will print the output 9 4.
D:
The program will print the output 100 100.
Answer: D
No answer description is available. Let's discuss.
What will be the output of the program given below?
#include<iostream.h> 
class BixBase
{
    int x;
    public:
    BixBase(int xx = 0)
    {
        x = xx; 
    }
    void Display()
    {
        cout<< x ;
    }
};
class BixDerived : public BixBase
{
    int y; 
    public:
    BixDerived(int yy = 0)
    {
        y = yy;
    }
    void Display()
    {
        cout<< y ;
    }
};
int main()
{
    BixBase objBase(10); 
    BixBase &objRef = objBase;

    BixDerived objDev(20); 
    objRef = objDev;

    objDev.Display(); 
    return 0; 
}
A:
0
B:
10
C:
20
D:
Garbage-value
Answer: C
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class ExamAdept
{
    int a, b, c; 
    public:
    void SetValue(int x, int y ,int z)
    {
        a = x;
        b = y;
        c = z;
    } 
    void Display()
    {
        cout<< a << " " << b << " " << c;
    } 
}; 
int main()
{
    ExamAdept objBix;
    int x  = 2;
    int &y = x;
    y = 5;
    objBix.SetValue(x, ++y, x + y);
    objBix.Display();
    return 0; 
}
A:
The program will print the output 5 6 10.
B:
The program will print the output 6 6 10.
C:
The program will print the output 6 6 12.
D:
It will result in a compile time error.
Answer: B
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int x, y; 
class BixTest
{
    public:
    BixTest(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
        Display(); 
    } 
    void Display()
    {
        cout<< x << " " << y << " ";
    }
};
int main()
{
    BixTest objBT(10, 20); 
    int &rx = x; 
    int &ry = y; 
    ry = x;
    rx = y;
    cout<< rx--; 
    return 0; 
}
A:
The program will print the output 0 0 10.
B:
The program will print the output 10 20 10.
C:
The program will print the output 10 20 9.
D:
It will result in a compile time error.
Answer: B
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int i, j; 
class ExamAdept
{
    public:
    ExamAdept(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    ExamAdept objBix(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}
A:
The program will print the output 0 11 21.
B:
The program will print the output 10 11 11.
C:
The program will print the output 10 11 21.
D:
The program will print the output 10 11 12.
Answer: B
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz