Recall & Review
beginner
What is a one-dimensional array in C++?
A one-dimensional array in C++ is a collection of elements of the same type stored in contiguous memory locations, accessed by a single index.
Click to reveal answer
beginner
How do you declare a one-dimensional array of 5 integers in C++?
You declare it like this:
int arr[5]; which creates an array named arr with 5 integer elements.Click to reveal answer
beginner
How do you access the third element of an array named
arr?You access it using the index 2:
arr[2] because array indexing starts at 0.Click to reveal answer
intermediate
What happens if you try to access an array element outside its declared size?
Accessing outside the array size leads to undefined behavior, which can cause errors or unexpected results because you read or write memory not allocated for the array.
Click to reveal answer
beginner
How can you initialize a one-dimensional array with values at the time of declaration?
You can initialize it like this:
int arr[3] = {10, 20, 30}; which sets the first element to 10, second to 20, and third to 30.Click to reveal answer
What is the index of the first element in a C++ array?
✗ Incorrect
In C++, array indexing always starts at 0.
Which of the following declares an array of 10 doubles?
✗ Incorrect
The correct syntax for declaring an array of 10 doubles is
double arr[10];.What will happen if you access arr[5] in an array declared as int arr[5];?
✗ Incorrect
Accessing arr[5] is outside the bounds (valid indices are 0 to 4), causing undefined behavior.
How do you initialize an array with values 1, 2, 3 in C++?
✗ Incorrect
The correct way is
int arr[3] = {1, 2, 3};.What type of elements can a one-dimensional array hold?
✗ Incorrect
Arrays hold elements all of the same data type.
Explain what a one-dimensional array is and how you use it in C++.
Think about a row of boxes where each box holds a value.
You got /4 concepts.
Describe how to declare, initialize, and access elements in a one-dimensional array.
Imagine labeling and filling boxes, then picking a box by its number.
You got /4 concepts.