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 = p;
cout<< p;
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 = p;
cout<< p;
return 0;
}
a) 5
b) Run-time error
c) Segmentation fault
d) Compile-time error

Answer: d
Explanation: A pointer cannot be directly assigned to references, because types of pointer(int*) and reference(int) are different here. You need to think before assigning two variable of different types otherwise the program throws error.

Join The Discussion