Open In App

Data Structures | Array | Question 2

What will the output of the below code?




#include <iostream>
using namespace std;
 
int main()
{
 
    int arr[2] = { 1, 2 };
    cout << 0 [arr] << ", " << 1 [arr] << endl;
    return 0;
}




public class Main {
    public static void main(String[] args) {
        int[] arr = {1, 2};
        System.out.println(arr[0] + ", " + arr[1]);
    }
}

(A)



1, 2

(B)



Syntax error

(C)

Run time error

(D)

None


Answer: (A)
Explanation:

0[arr]] is a different way to represent array element, which represents the first element of the array.
similarly, 1[arr] is a different way to represent array element, which represents the second element of the array.

Hence the correct output is (A)

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :