- AA collection of different data types
- BA collection of same data type elements stored in contiguous memory
- CA function that stores multiple values
- DA pointer variable
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
An array in C++ is used to store multiple values of the same data type in a continuous block of memory.
This allows easy access to elements using an index.
Example:
int a[3] = {10, 20, 30};
All elements are integers and are stored next to each other in memory.
Why other options are incorrect
A) Different data types ❌ → Arrays store only same data type
C) Function ❌ → Arrays are not functions
D) Pointer variable ❌ → An array is not a pointer (though related)
Correct Answer:
B) A collection of same data type elements stored in contiguous memory
Description:
Arrays store multiple values of the same type in consecutive memory locations for efficient access.
To declare an array in C++, you must specify:
The data type
The array name
The number of elements inside square brackets [ ]
int arr[10];
This correctly declares an array that can store 10 integers.
Why other options are incorrect
A) int arr; ❌ → Declares a single integer, not an array
B) int arr(10); ❌ → Not valid array syntax
D) array int arr[10]; ❌ → Invalid C++ syntax
Correct Answer: C) int arr[10];
Description:int arr[10] is the correct way to declare an array of 10 integers in C++.
In C++, array indexing always starts from 0.
That means:
The first element of an array is accessed using index 0
The second element uses index 1, and so on
Example:
int a[3] = {10, 20, 30};
Index-wise access:
a[0] = 10
a[1] = 20
a[2] = 30
Correct Answer: B) 0
Description:
C++ uses zero-based indexing for arrays.
In C++, array indexing starts from 0.
For the array:
int a[5];
Total elements = 5
Index values = 0, 1, 2, 3, 4
So, the last index is 4, not 5.
Correct Answer: B) 4
Description:
The highest index of an array is always size − 1.
The declaration:
int x[20];
creates an array that can store 20 elements.
The number inside the brackets [20] specifies the total number of elements
Array indexing starts from 0
Valid indices range from 0 to 19
So even though the last index is 19, the array still contains 20 elements.
Correct Answer: C) 20
Description:x[20] means the array size is 20, not 19.
The for loop is most commonly used to access array elements because:
The number of elements in an array is usually known
It allows easy control of the index using initialization, condition, and increment
Example:
for (int i = 0; i < 5; i++) {
cout << arr[i];
}
Other loops (while, do-while) can also be used, but they are less convenient for array traversal.
A switch loop cannot be used to iterate over arrays.
Correct Answer: C) for loop
In C++, accessing an array index outside its declared size does not automatically give a compiler error or a guaranteed runtime error.
Instead, it results in undefined behavior.
This means:
The program may print a garbage value
It may crash
Or it may seem to work incorrectly
The behavior can vary from system to system
C++ does not perform bounds checking on arrays.
Correct Answer: D) Undefined behavior
Description:
Accessing an array index beyond its size leads to unpredictable results, which is called undefined behavior in C++.
In C++, an array must be declared with a size and initialized using curly braces { }.
int a[3] = {1, 2, 3};
This statement:
Declares an array of 3 integers
Correctly initializes all elements
Why other options are wrong
A) int a = {1,2,3}; ❌ → a is not an array
B) int a[3] = 1,2,3; ❌ → Missing { }
D) int a(3) = {1,2,3}; ❌ → Invalid array syntax
Correct Answer: C) int a[3] = {1,2,3};
In C++, array indexing starts from 0.
int a[3] = {10, 20, 30};
Index-wise values:
a[0] = 10
a[1] = 20
a[2] = 30
The statement:
cout << a[1];
prints the value at index 1, which is 20.
Correct Answer: B) 20
Answer: C
A two-dimensional array in C++ stores data in the form of rows and columns, just like a table.
Because of this row–column structure, a two-dimensional array is commonly referred to as a matrix.
Why other options are incorrect
A) Single array ❌
A single array refers to a one-dimensional array, not a 2D array.
B) Pointer array ❌
A pointer array is an array of pointers, which is different from a 2D array.
D) String ❌
A string is a character array, not necessarily two-dimensional.