31
What is the output of the following Python code: array = [1, 2, 3]; print(array[-1])
A)
1
B)
2
C)
3
D)
IndexError
Answer & Solution
Answer: Option
C
32
Which of the following is a method to find the length of an array in C++?
A)
size()
B)
length()
C)
sizeof(array)/sizeof(array[0])
D)
array.size()
Answer & Solution
Answer: Option
C
33
Which of the following is true about array-based lists?
A)
They allow for easy insertion/deletion
B)
They offer O(1) access time by index
C)
They automatically resize
D)
They do not require contiguous memory
Answer & Solution
Answer: Option
B
34
In which scenario would you prefer to use an array over a linked list?
A)
When you need constant time access by index
B)
When you need dynamic resizing
C)
When you frequently insert elements
D)
When you frequently delete elements
Answer & Solution
Answer: Option
A
35
How do you initialize an array in Java with specific values?
A)
int[] array = new int[5];
B)
int[] array = {1, 2, 3, 4, 5};
C)
int array[] = new int[5];
D)
int array[] = {1, 2, 3, 4, 5};
Answer & Solution
Answer: Option
B
36
What is the correct syntax to access the third element of an array in C?
A)
array[2]
B)
array[3]
C)
array(2)
D)
array.get(2)
Answer & Solution
Answer: Option
A
37
Which of the following languages does not support multidimensional arrays directly?
A)
C
B)
Java
C)
Python
D)
JavaScript
Answer & Solution
Answer: Option
D
38
What is a jagged array in C#?
A)
An array with rows of different lengths
B)
A multi-dimensional array
C)
An array containing different data types
D)
An array that can dynamically resize
Answer & Solution
Answer: Option
A
39
Which method is used to sort an array in Python?
A)
array.sort()
B)
sort(array)
C)
array.order()
D)
Arrays.sort(array)
Answer & Solution
Answer: Option
A
40
How do you remove an element from an array in JavaScript?
A)
array.remove(index);
B)
array.delete(index);
C)
array.splice(index, 1);
D)
array.pop(index);
Answer & Solution
Answer: Option
C