What will be the output of the following C++ code? [code] #include <stdio.h> #include<iostream> using namespace std; int

What will be the output of the following C++ code?
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.
 

Tìm kiếm

Back
Top