C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 22)
22.
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; 
}
The program will print the output 0 0 10.
The program will print the output 10 20 10.
The program will print the output 10 20 9.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

Ayush said:   1 decade ago
Since ry has been assigned x ie it now points to variable x.
And since reference variable ry is assigned the value of x.

Hence y =x;
So answer is 10 20 10.

Am I correct?
(1)

Rishi said:   1 decade ago
How?

Jaideep Gupta said:   10 years ago
I think the answer would be 10, 20, 19.

Tarun said:   8 years ago
The value of ry-- will be 9 and value of rx-- will be 19.

RazvanIacob said:   8 years ago
When you make this assignment ry=x, automatically y will be 10.

Post your comments here:

Your comments will be displayed after verification.