Question 1
Why the below code snippet provides error?
#include <iostream>
using namespace std;
int main() {
int arr[3][2] ={{1,2,3},{4,5,6},{7,8,9}};
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
cout<<arr[i][j]<<endl;
return 0;
}
arr[i][j] is is not declared
there are no any braces used inside for loop
We have declared an array of 3 rows and 2 columns, but assigned value to 3 rows and 3 columns.
None
Question 2
What is the size of int arr[15]; if we assume that int is 4 bytes?
15
11
12
60
Question 3
When does the ArrayIndexOutOfBoundsException occur?
Compile time
Run time
Not an Exception
None
Question 4
The first Index of the array typically starts from -----
-1
1
0
None
Question 5
When the array has free unused memory, which method can be used to free up the extra memory?
free()
shrinkSize()
growSize()
None
Question 6
Which method is used to access elements in an array?
Sequential
Random
Logarithmic
Alternative
Question 7
What is the time complexity for inserting/deleting at the beginning of the array?
O(1)
O(logN)
O(NlogN)
O(N)
Question 8
What will do the below code snippet?
#include <iostream>
using namespace std;
int main()
{
int m = 3, n = 4, c = 0;
int* arr = new int[m * n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
*(arr + i * n + j) = ++c;
}
}
return 0;
}
It will create a 1d array and assign value to it.
It will create a 1d array of size m*n and assign value to it.
It will create a 1d dynamic array and assign value to it.
It will create a dynamic 2d array and assign value to it.
Question 9
In C++, we can create a dynamic array using the ______keyword.
array
this
super
new
Question 10
How can we create a dynamic array in C?
vector( )
dynamic_array( )
malloc()
None
There are 30 questions to complete.