# Array and Array Operations

• Our quick test is a 40-point assessment designed to gauge your understanding of key concepts. It features 10 multiple-choice questions.
• Each correct answer earns you 4 points, while each wrong answer deducts 1 point.
• This test helps you identify areas of strength and areas needing improvement.

Good luck!

#### 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``

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?

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``

Score Range: 35-40 points Remarks: Excellent job! You aced the test and showed a strong grasp of the material. Keep up the fantastic work!

Score Range: 30-34 points Remarks: Great work! You did very well and demonstrated a solid understanding of the concepts. Just a little more effort and you’ll hit perfection.