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>
using namespace std;
int main()
{
int n = 5;
void *p = & n;
int *pi = static_cast< int*>(p);
cout << *pi << endl; return 0; }

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main()
{
int n = 5;
void *p = & n;
int *pi = static_cast< int*>(p);
cout << *pi << endl; return 0; }
a) 5
b) 6
c) compile time error
d) runtime error

Answer: a
Explanation: We just casted this from void to int, so it prints 5
Output:
5

Join The Discussion