Home » C++ Programming » Arrays » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int p = 15, q = 11, r = 12;
    int array[3] = {&p, &q, &r};
    cout << *array[*array[1] - 8];
    return 0;
    }
    1. 11
    2. 12
    3. 15
    4. Compilation Error
    5. Garbage value
Correct Option: D

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’

In function 'int main()':
6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
6:35: error: invalid conversion from 'int*' to 'int' [-fpermissive]
7:9: error: 'cout' was not declared in this scope
7:32: error: invalid type argument of unary '*' (have 'int')



Your comments will be displayed only after manual approval.