S
Shraddha
As references are behaving like a constant pointer...And we can not
change the value of reference once set...then how is following program
works...This program gives the output as 10 and 20....Actually I was
expecting an error....
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class abc
{
public:
int x;
public:
abc()
{
}
abc(int y)
{
x=y;
}
/*void assign(int y)
{
x=y;
} */
};
int main()
{
abc o1(10),o2(20);
abc &r=o1;
clrscr();
cout<<r.x<<"\n\n";
r=o2;
cout<<r.x;
getch();
return 0;
}
change the value of reference once set...then how is following program
works...This program gives the output as 10 and 20....Actually I was
expecting an error....
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
class abc
{
public:
int x;
public:
abc()
{
}
abc(int y)
{
x=y;
}
/*void assign(int y)
{
x=y;
} */
};
int main()
{
abc o1(10),o2(20);
abc &r=o1;
clrscr();
cout<<r.x<<"\n\n";
r=o2;
cout<<r.x;
getch();
return 0;
}