Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
int a = 5;
int &q = a;
cout<<&a << endl;
cout<<&q << endl;
return 0;
}

What will be the output of the following C++ code?
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char const *argv[])
{
int a = 5;
int &q = a;
cout<<&a << endl;
cout<<&q << endl;
return 0;
}
a) 5
5
b) Address of p followed by 5 in next line
c) 5 followed by Address of a in next line
d) Address of a followed by Address of a in next line

Answer: d
Explanation: Both variable and reference shares the same addres so the output will be two times the address of a, because references are other name for same variable not a new variable with separate memory.

Join The Discussion