Data Structures | Array | Question 2
What will the output of the below code?
C++
#include <iostream>
using namespace std;
int main()
{
int arr[2] = { 1, 2 };
cout << 0 [arr] << ", " << 1 [arr] << endl;
return 0;
}
|
Java
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
Last Updated :
28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...