Computer

Array MCQs

Practice Array MCQs for competitive exams.

Array MCQs

Practice questions from this topic.

Which of these is an incorrect Statement?

  1. A. It is necessary to use new operator to initialize an array
  2. B. Array can be initialized using comma separated expressions surrounded by curly braces
  3. C. Array can be initialized when they are declared
  4. D. None of the mentioned
Report Error

What will be the output of the following Java code? class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 5); } }

  1. A. 8
  2. B. 9
  3. C. 10
  4. D. 11
Report Error

Which of these is necessary to specify at time of array initialization?

  1. A. Row
  2. B. Column
  3. C. Both Row and Column
  4. D. None of the mentioned
Report Error

What will be the output of the following Java code? class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } }

  1. A. 11
  2. B. 10
  3. C. 13
  4. D. 14
Report Error

What will be the output of the following Java code? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + ""); } } }

  1. A. 1 2 3 4 5 6 7 8 9 10
  2. B. 0 1 2 3 4 5 6 7 8 9 10
  3. C. i j k l m n o p q r
  4. D. i i i i i i i i i i
Report Error

What will be the output of the following Java code? class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } }

  1. A. 3
  2. B. 0
  3. C. 6
  4. D. 1
Report Error

What will be the output of the following Java code? class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i; System.out.print(array_variable[i] + " "); i++; } } }

  1. A. 0 2 4 6 8
  2. B. 1 3 5 7 9
  3. C. 0 1 2 3 4 5 6 7 8 9
  4. D. 1 2 3 4 5 6 7 8 9 10
Report Error

What will be the output of the following Java code? int arr[] = new int [5]; System.out.print(arr);

  1. A. 0
  2. B. value stored in arr[0]
  3. C. 00000
  4. D. Class name@ hashcode in hexadecimal form
Report Error

Which of these is an incorrect array declaration?

  1. A. int arr[] = new int[5]
  2. B. int [] arr = new int[5]
  3. C. int arr[] = new int arr[5]
  4. D. int arr[] = int [5] new
Report Error

Which of these operators is used to allocate memory to array variable in Java?

  1. A. malloc
  2. B. alloc
  3. C. new
  4. D. new malloc
Report Error

Predict the output: public class Test{ public static void main(String... args){ int[] index = new int[5]; System.out.println(index instanceof Object); } }

  1. A. true
  2. B. false
  3. C. Compilation fails with an error at line 3
  4. D. Compilation fails with an error at line 4 E. None of these
Report Error

What is the value of a[1] after the following code is executed? int[] a = {0, 2, 4, 1, 3}; for(int i = 0; i < a.length; i++) a[i] = a[(a[i] + 3) % a.length];

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 3 E. 4
Report Error