Recall & Review
beginner
What is the time complexity of accessing an element at a specific index in an array?
Accessing an element at a specific index in an array takes constant time, O(1), because arrays allow direct access using the index.
Click to reveal answer
beginner
How do you update the value at index 3 in an integer array named
arr in C?You update the value by assigning a new value using the index: <br>
arr[3] = new_value;Click to reveal answer
intermediate
What happens if you try to access or update an index outside the array bounds in C?
Accessing or updating an index outside the array bounds causes undefined behavior, which can lead to program crashes or incorrect results.
Click to reveal answer
intermediate
Explain why arrays provide fast access to elements compared to linked lists.
Arrays store elements in contiguous memory locations, so accessing an element by index is direct and fast (O(1)). Linked lists require traversal from the head to reach an element, which takes O(n) time.
Click to reveal answer
advanced
In C, how is the expression
arr[i] interpreted internally?The expression
arr[i] is interpreted as *(arr + i), which means accessing the memory location at the base address of arr plus i times the size of the element.Click to reveal answer
What is the result of accessing
arr[5] if arr has size 5?✗ Incorrect
Array indices in C go from 0 to size-1. Accessing index 5 in a size 5 array is out of bounds and causes undefined behavior.
Which of the following is the correct way to update the 2nd element of an array
arr to 10?✗ Incorrect
Array indices start at 0, so the 2nd element is at index 1. The correct syntax is arr[1] = 10;
What is the time complexity to update an element at a given index in an array?
✗ Incorrect
Updating an element at a specific index in an array is a direct operation and takes constant time O(1).
In C, what does the expression
*(arr + i) mean?✗ Incorrect
In C,
arr[i] is equivalent to *(arr + i), which accesses the element at index i.Which of these statements about arrays is FALSE?
✗ Incorrect
Arrays in C have fixed size and do not resize automatically. Dynamic resizing requires other data structures.
Describe how to access and update an element at a specific index in a C array.
Think about how you use arr[i] in C.
You got /5 concepts.
Explain what happens if you try to access or update an array element outside its valid index range in C.
Consider memory safety and C language behavior.
You got /4 concepts.
