Which two are valid declarations of a two-dimensional array?

Which two are valid declarations of a two-dimensional array?

Which two are valid declarations of a two-dimensional array?

A.
int[][] array2D;

B.
int[2][2] array2D;

C.
int array2D[];

D.
int[] array2D[];

E.
int[][] array2D[];

Explanation:

int[][] array2D; is the standard convention to declare a 2-dimensional integer array.
int[] array2D[]; works as well, but it is not recommended.
Incorrect answers:
int[2][2] array2D;
The size of the array cannot be defined this way.
int array2D[]; is good definition of a one-dimensional array.
int[] []array2D[];is good definition of a three-dimensional array.



Leave a Reply 0

Your email address will not be published. Required fields are marked *