C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 10)
10.
What will be the output of the following program?
#include<iostream.h>
class BixTest
{
public:
BixTest(int &x, int &y)
{
x++;
y++;
}
};
int main()
{
int a = 10, b = 20;
BixTest objBT(a, b);
cout<< a << " " << b;
return 0;
}
Discussion:
5 comments Page 1 of 1.
Akshay said:
9 years ago
It's call by refrence. So, value be reflected in originals.
Gurjot said:
9 years ago
The function isn't returning any values so the answer should be 10 20 and not 11 21.
Naman said:
10 years ago
But the function is not returning any pass d by reference.
Kapil Kr Deol said:
1 decade ago
Because in the constructor BixTest (int &x, int &y), We are passing taking value at reference, after execution of constructor it will change value at address to x++, y++ and reflected value will receive in main.
Output: 11 21.
Output: 11 21.
Jaison Joseph said:
1 decade ago
What about scope and life of variable a and b ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers