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) Run time error
d) Compile time error

Answer: d
Explanation: References uses no * operator to access the value of variables it is refering to therefore no program gives error as we are using * operator.

Join The Discussion