C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 16)
16.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Bix
{
    int x, y; 
    public:
    Bix(int x, int y)
    {
        this->x = x;
        this->y = y;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x = 50;
    int &y = x ;
    Bix b(y, x);
    return 0; 
}
The program will print the output 50 50.
The program will print the two garbage values.
It will result in a compile time error.
The program will print nothing.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
5 comments Page 1 of 1.

PRIYANK said:   1 decade ago
The program will print nothing because we are not calling "Display()".

Rajesh reddy said:   1 decade ago
Don't print anything because externally we don't call any display function.

Adi said:   1 decade ago
In the function definition, shouldn't it be Bix (int &x, int y) instead of Bix (int x, int y) ?

So compiler error should be there. Please clarify.

Shambhu said:   8 years ago
std::cout << x << y << endl; must be used or std namespace must be added.

Vishal Singh said:   7 years ago
@Adi.

Even if we add a b.Display() call in the program it does not throw any error, so the declaration is correct and it returns values as 50 50.

Post your comments here:

Your comments will be displayed after verification.