C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 13)
13.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
struct Bix
{
    short n;
};
int main()
{
    Bix b;
    Bix& rb = b;
    b.n = 5;
    cout << b.n << " " << rb.n << " ";
    rb.n = 8;
    cout << b.n << " " << rb.n;
    return 0; 
}
It will result in a compile time error.
The program will print the output 5 5 5 8.
The program will print the output 5 5 8 8.
The program will print the output 5 5 5 5.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Ronit said:   10 years ago
Explain it.

Anonymous said:   8 years ago
Here b=&rb.

In the question, its mentioned that b=5 therefore, rb=5.
Then rb is initialized to 8 so b = 8.
rb value will be assigned to b.
So, it is 5 5 8 8.

Rishabh said:   7 years ago
It will result in compile-time error because Bix b is not correct. It has to be struct Bix b;.

Julien said:   6 years ago
You can use "Bix b;", it is correct in C++ (not in C).

But yes it will not compile as well as other questions(It's strange that nobody point that). They don't use any namespace, so cout is unknwon.

Post your comments here:

Your comments will be displayed after verification.