C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 21)
21.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int i, j; 
class IndiaBix
{
    public:
    IndiaBix(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    IndiaBix objBix(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}
The program will print the output 0 11 21.
The program will print the output 10 11 11.
The program will print the output 10 11 21.
The program will print the output 10 11 12.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
4 comments Page 1 of 1.

Venkat said:   9 years ago
Parameterised constructor is invoked, in that j=x ; i.e., j=10 will assign (here j is global)
j= 10 will be printed by calling display().

int &s = i; // i=10
int &z = j; // j=10 (here j is global, value of j is 10
i++; // 11
cout<< s-- << " " << ++z; // 11 11

Pkc said:   9 years ago
Values of x and y are overwritten.

It becomes x=10, y=20.

Amit said:   10 years ago
Please explain it to me. I can't get it.
(1)

Somebody said:   9 years ago
Yeah! someone explain it.
(1)

Post your comments here:

Your comments will be displayed after verification.