C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 17)
17.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y;
public:
void SetValue(int &xx, int &yy)
{
x = xx++;
y = yy;
cout<< xx << " " << yy;
}
};
int main()
{
int x = 10;
int &y = x;
IndiaBix objBix;
objBix.SetValue(x , y);
return 0;
}
Discussion:
6 comments Page 1 of 1.
Mani said:
2 years ago
It should be 10 10.
Both xx and yy are referring to x, but the increment is given only to 'xx' which is why it should be 11 since it is a post increment the result will be displayed as 10 only and the value stored is 11 and coming to yy it is displayed as 10.
Both xx and yy are referring to x, but the increment is given only to 'xx' which is why it should be 11 since it is a post increment the result will be displayed as 10 only and the value stored is 11 and coming to yy it is displayed as 10.
Student said:
2 years ago
Note:
The code print xx and yy, instead of x and y.
x should be 10, and y should be 11.
However, xx and yy are both 11.
The code print xx and yy, instead of x and y.
x should be 10, and y should be 11.
However, xx and yy are both 11.
Domonkos said:
4 years ago
It is xx++ not ++xx.
So the first output is 10.
Second output is 11 as xx and yy has the same reference giving yy value to y actually means giving xx value to y but xx has been incremented by 1 to 11.
So the first output is 10.
Second output is 11 as xx and yy has the same reference giving yy value to y actually means giving xx value to y but xx has been incremented by 1 to 11.
Mehak said:
7 years ago
How can it be posssible, as it is x++ not ++x?
So acc to me output must be 10, 10.
So acc to me output must be 10, 10.
Rishi said:
1 decade ago
How x is taken as a reference in fun bix ?
PRIYANK said:
1 decade ago
xx++ makes its value 11 and as yy referring to xx, its value also becomes 11.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers