Welcome to the C++ Arrays Quiz! This extensive quiz covers a wide range of topics from basic to advance related to arrays in C++. Each question comes with a clear explanation, helping you understand not just the correct answer but why it's correct. Test your knowledge and strengthen your understanding of how arrays work, from basic declarations to advanced manipulations.
Question 1
What is an array in C++?
A collection of elements of different types
A collection of elements of the same type
A collection of functions
None of the above
Question 2
How do you declare an array of integers with 5 elements in C++?
int array[5];
array int[5];
int[5] array;
array[5] int;
Question 3
What will be the output of the following code?
#include <iostream>
using namespace std;
int main() {
int arr[5] = {1, 2, 3, 4, 5};
cout << arr[2];
return 0;
}
1
2
3
4
Question 4
Which of the following correctly initializes an array of 3 integers to 0?
int arr[3] = {};
int arr[3] = {0, 0, 0};
int arr[3] = {0};
All of the above
Question 7
How do you pass an array to a function in C++?
By copying
By value
By pointer
By name
Question 8
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {
int arr[3] = {1, 2};
for(int i = 0; i < 3; i++)
cout << arr[i] << " ";
return 0;
}
1 2 3
1 2 1
1 2 0
Compilation error
Question 9
What will be the output of the following code?
#include <iostream>
using namespace std;
void modifyArray(int arr[], int size) {
for(int i = 0; i < size; i++) {
arr[i] += 5;
}
}
int main() {
int arr[3] = {1, 2, 3};
modifyArray(arr, 3);
for(int i = 0; i < 3; i++) {
cout << arr[i] << " ";
}
return 0;
}
1 2 3
6 7 8
1 7 3
Compilation error
Question 10
Which of the following are true about multidimensional arrays in C++?
They are arrays of arrays
The syntax to declare a 2D array is type arrayName[rows][columns];
They can have two or more dimensions
All of the above
There are 30 questions to complete.