C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 26)
26.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
public:
int x, y;
IndiaBix(int xx = 10, int yy = 20)
{
x = xx;
y = yy;
}
void Exchange(int *, int *);
};
int main()
{
IndiaBix objA(30, 40);
IndiaBix objB(50);
objA.Exchange(&objA.x, &objB.y);
cout<< objA.x << " " << objB.y << endl;
return 0;
}
void IndiaBix::Exchange(int *x, int *y)
{
int t;
t = *x;
*x = *y;
*y = t ;
}
Discussion:
2 comments Page 1 of 1.
Keerthu said:
1 decade ago
objA -> x=30 y=40 objB x=50 y=20.
objA.x is 30 and objB.y is 20.
So objA.Exchange(&objA.x, &objB.y);
Is objA.x=20 objB.y=30.
objA.x is 30 and objB.y is 20.
So objA.Exchange(&objA.x, &objB.y);
Is objA.x=20 objB.y=30.
Chanchla said:
9 years ago
When we pass value through object first part will contain 30 replays 10 by 30 as 1 value and in and call, there is no b y value so it takes its value from constructor.
We call onjA(30,20); in the function value exchange because it is call by reference.
We call onjA(30,20); in the function value exchange because it is call by reference.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers