1. What is the index of the first element in a typical array?
a) -1
b) 0
c) 1
d) Depends on the language
2. How do you access the third element of an array named arr
?
a)
arr(3)
b)
arr[2]
c)
arr[3]
d)
arr.get(3)
3. Which operation is used to add an element at the end of an array in most programming languages?
a)
push
b)
append
c)
insert
d)
add
4. What is the time complexity of accessing an element in an array?
a) O(n)
b) O(log n)
c) O(1)
d) O(n log n)
5. What is the result of the following operation in Python:
arr = [1, 2, 3]; arr[1] = 4
a)
[1, 2, 3]
b)
[1, 4, 3]
c)
[1, 3, 4]
d)
IndexError
6. Given an array arr = [2, 4, 6, 8, 10]
, what will be the result of the operation arr.splice(2, 1)
in JavaScript?
arr.splice(2, 1)
a)
[2, 4, 8, 10]
b)
[4, 6, 8, 10]
c)
[2, 4, 6, 8, 10]
d)
[2, 4, 8]
7. What is the result of the following Python code snippet?
arr = [1, 2, 3, 4, 5]
arr[::2] = [9, 9, 9]
a)
[9, 2, 9, 4, 9]
b)
[9, 9, 9, 9, 9]
c)
[1, 2, 3, 4, 5]
d)
ValueError
8. What does the following C++ code snippet do?
int arr[] = {10, 20, 30, 40};
int *ptr = arr + 2;
cout << *ptr << endl;
a) Prints 10
b) Prints 20
c) Prints 30
d) Throws an error
9. Which of the following operations can be used to remove the last element of an array in JavaScript?
a)
arr.pop()
b)
arr.remove()
c)
arr.shift()
d)
arr.delete()
10. What will be the output of the following Java code?
int[] arr = {1, 2, 3, 4, 5};
System.out.println(arr.length);
a)
4
b)
5
c)
6
d)
Throws an error