Recall & Review
beginner
What is array initialization in C++?
Array initialization means giving values to the elements of an array when you create it. This sets the starting values for the array.
Click to reveal answer
beginner
How do you initialize an integer array of size 5 with values 1, 2, 3, 4, 5 in C++?
int arr[5] = {1, 2, 3, 4, 5};
Click to reveal answer
intermediate
What happens if you initialize an array with fewer values than its size?
The remaining elements are set to zero automatically.
Click to reveal answer
intermediate
Can you initialize an array without specifying its size? How?
Yes. You can let the compiler count the values: int arr[] = {1, 2, 3}; The size becomes 3 automatically.Click to reveal answer
intermediate
What is the difference between partial initialization and no initialization of an array?
Partial initialization sets some elements and the rest become zero. No initialization leaves elements with garbage (random) values.
Click to reveal answer
How do you initialize an array of 4 integers with all zeros in C++?
✗ Incorrect
Using {0} sets the first element to zero and the rest are also zero by default. Using {} also zero-initializes all elements.
What is the size of the array: int arr[] = {10, 20, 30}; ?
✗ Incorrect
The compiler counts the values and sets the size to 3.
If you write int arr[5] = {1, 2}; what are the values of arr[2], arr[3], and arr[4]?
✗ Incorrect
Elements not initialized explicitly are set to zero.
Which of these is NOT a valid way to initialize an array in C++?
✗ Incorrect
You must use braces {} to initialize arrays, not commas alone.
What is the value of arr[0] after this code? int arr[3] = {};
✗ Incorrect
Empty braces {} initialize all elements to zero.
Explain how to initialize an array in C++ and what happens if you provide fewer values than the array size.
Think about using braces {} and what the compiler does with missing values.
You got /3 concepts.
Describe the difference between initializing an array with all zeros and leaving it uninitialized.
Consider what values you get if you don't set any values explicitly.
You got /3 concepts.