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 *p = &a;
int &q = a;
cout<< p<< 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 *p = &a;
int &q = a;
cout<< p<< endl;
cout<< q<< endl;
return 0;
}
a) Address of a followed by 5 in next line
b) Address of p followed by 5 in next line
c) Address of a followed by Address of a in next line
d) Address of p followed by Address of q in next line

Answer: a
Explanation: Pointer p stores the address of variable whereas q is alias for variable a therefore when p is printed it prints the address of a and when q is printed value of a is printed.

Join The Discussion