C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 20)
20.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
    IndiaBix(int &xx, int &yy)
    {
        x = xx;
        y = yy;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x1 = 10; 
    int &p = x1;
    int y1 = 20; 
    int &q = y1; 
    IndiaBix objBix(p, q); 
    return 0; 
}
It will result in a compile time error.
The program will print the output 10 20.
The program will print two garbage values.
The program will print the address of variable x1 and y1.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
3 comments Page 1 of 1.

Ganesh maheshwari said:   7 years ago
The correct answer is A.

Because p and q are pointers they hold address and address only store by the pointer from above code we are converting the pointer into reference which is incorrect.

Shradha said:   7 years ago
Because here p & q actually containing values of x1 & y1.

Vision said:   8 years ago
Can anyone explain this?

Post your comments here:

Your comments will be displayed after verification.