Recall & Review
beginner Click to reveal answer
What is array traversal?
Array traversal means visiting each element in an array one by one, usually from the first element to the last.
beginner Click to reveal answer
How do you traverse an array forwards in C?
Use a for loop starting from index 0 up to the last index, accessing each element in order.
beginner Click to reveal answer
What is reverse traversal of an array?
Reverse traversal means visiting array elements starting from the last element down to the first.
intermediate Click to reveal answer
Why is it important to know array traversal patterns?
Knowing traversal patterns helps to solve problems like searching, sorting, and modifying arrays efficiently.
beginner Click to reveal answer
Show the C code snippet to traverse an array forwards and print each element.
int arr[] = {1, 2, 3, 4};
int n = 4;
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
// Output: 1 2 3 4
Which index does array traversal in C usually start from?
✗ Incorrect
In C, arrays start at index 0, so traversal usually begins at 0.
What is the last index of an array with size n?
✗ Incorrect
Array indices go from 0 to n-1, so the last index is n-1.
Which loop is commonly used for array traversal in C?
✗ Incorrect
For loops are simple and clear for traversing arrays.
What happens if you traverse an array beyond its last index?
✗ Incorrect
Accessing beyond array bounds causes undefined behavior or crashes.
How do you traverse an array in reverse order?
✗ Incorrect
Reverse traversal starts at last index and moves backward to 0.
Explain how to traverse an array forwards and backwards in C.
Think about how the loop index changes in each case.
You got /4 concepts.
Why must you be careful not to access array elements outside their valid indices during traversal?
Consider what happens if you read or write outside the array.
You got /4 concepts.
