C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 15)
15.
Which of the following statement is correct?
Discussion:
4 comments Page 1 of 1.
Shrawan said:
3 years ago
@All.
According to me, the coding part is;
#include <iostream>
using namespace std;
int main()
{
int x=20,a=10;
int &b=a;
cout<<"\n\n Value of b = "<<b;
b=x;
cout<<"\n\n Value of b = "<<b;
cout<<"\n\n Value of a = "<<a;
cout<<"\n\n address of b = "<<&b;
cout<<"\n\n address of a = "<<&a;
cout<<"\n\n address of x = "<<&x;
return 0;
}
According to me, the coding part is;
#include <iostream>
using namespace std;
int main()
{
int x=20,a=10;
int &b=a;
cout<<"\n\n Value of b = "<<b;
b=x;
cout<<"\n\n Value of b = "<<b;
cout<<"\n\n Value of a = "<<a;
cout<<"\n\n address of b = "<<&b;
cout<<"\n\n address of a = "<<&a;
cout<<"\n\n address of x = "<<&x;
return 0;
}
Krushna said:
5 years ago
How? Explain in detail.
Rishabh. said:
8 years ago
@Arko.
It is a eference to the same variable only the value stored is changing.
It is a eference to the same variable only the value stored is changing.
Arko / Judhajit said:
1 decade ago
Option B is also correct.(According to this working code)
#include<iostream.h>
int main()
{
int x=20,a=10;
int &b=a;
cout<<"\n\n Value of b = "<<b;
b=x;
cout<<"\n\n Value of b = "<<b;
return 0;
}
OUTPUT:
Value of b = 10.
Value of b = 20.
Hence, "Once a reference variable(variable 'b' in this case) has been defined to refer to a particular variable(variable 'a') it can refer to any other variable(variable'x')." - is TRUE!.
#include<iostream.h>
int main()
{
int x=20,a=10;
int &b=a;
cout<<"\n\n Value of b = "<<b;
b=x;
cout<<"\n\n Value of b = "<<b;
return 0;
}
OUTPUT:
Value of b = 10.
Value of b = 20.
Hence, "Once a reference variable(variable 'b' in this case) has been defined to refer to a particular variable(variable 'a') it can refer to any other variable(variable'x')." - is TRUE!.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers