Last Updated : 10 Apr, 2024

What is the output of the below program

#include <iostream>
using namespace std;

int main()
{
    
    int array2[5] = {2, 5, 4};
    int array3[] {2, 5, 4, 8, 6};
    
    cout << array2[3] << \" \" << array2[4] << endl;
    array2[3] = array3[3];                                        // line 1
    array2[4] = array3[4];                                       //  line 2
    cout << array2[3] << \" \" << array2[4];
    return 0;
}

(A) 0 8
0 6
(B) 0 0
0 0
(C) 0 0
8 6
(D) error in line 1 and line 2


Answer: (C)

Explanation: Elements at indexes 3, 4 of array2[] are 0, 0. After initialized with elements of array3[], array2[] also contains 8 and 6 at indexes 3 and 4.


Share your thoughts in the comments