Array and Array Operations | Data Structure MCQs


Which of the following is a correct way to declare a multidimensional array in Java?

   A.) int[][] arr;
   B.) int arr[][];
   C.) int []arr[];
   D.) All of the mentioned

Answer: Option 'D'

All the options are syntactically correct.


What is the output of the following piece of code?

public class array
	public static void main(String args[])
		int []arr = {1,2,3,4,5};

   A.) 3 and 5
   B.) 5 and 3
   C.) 2 and 4
   D.) 4 and 2

Answer: Option 'A'

Array indexing starts from 0.


Which of the following concepts make extensive use of arrays?

   A.) Binary trees
   B.) Scheduling of processes
   C.) Spatial locality
   D.) Caching

Answer: Option 'C'

Whenever a particular memory location is referred, it is likely that the locations nearby are also referred, arrays are stored as contigous blocks in memory, so if you want to access array elements, spatial locality makes it to access quickly.


How do you initialize an array in C?

   A.) int arr[3] = (1,2,3);
   B.) int arr(3) = {1,2,3};
   C.) int arr[3] = {1,2,3};
   D.) int arr(3) = (1,2,3);

Answer: Option 'C'

This is the syntax to initialize an array in C.


When does the ArrayIndexOutOfBoundsException occur?

   A.) Compile-time
   B.) Run-time
   C.) Not an error
   D.) None of the mentioned

Answer: Option 'B'

ArrayIndexOutOfBoundsException is a run-time exception and the compilation is error-free.

Array and Array Operations | Data Structure MCQs Download Pdf