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 <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] – 8];
return 0;
}

What will be the output of the following C++ code?
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int a = 5, b = 10, c = 15;
int arr[3] = {&a, &b, &c};
cout << *arr[*arr[1] - 8];
return 0;
}
a) 15
b) 18
c) garbage value
d) compile time error

Answer: d
Explanation: The conversion is invalid in this array. So it will arise error. The following compilation error will be raised: cannot convert from ‘int *’ to ‘int’ This is because &a, &b and &c represent int* whereas the array defined is of int type.

Join The Discussion