0
0
C++programming~5 mins

One-dimensional arrays in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A0
B1
C-1
DDepends on the array size
Which of the following declares an array of 10 doubles?
Adouble arr()
Bdouble arr;
Cint arr[10];
Ddouble arr[10];
What will happen if you access arr[5] in an array declared as int arr[5];?
AUndefined behavior
BReturns 0
CCompiler error
DReturns last element
How do you initialize an array with values 1, 2, 3 in C++?
Aint arr = {1, 2, 3};
Bint arr[3] = {1, 2, 3};
Cint arr(3) = {1, 2, 3};
Dint arr[] = 1, 2, 3;
What type of elements can a one-dimensional array hold?
AOnly integers
BElements of different data types
CElements of the same data type
DOnly characters
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.