Array Data Structure Quiz for Beginners

Last Updated :
Discuss
Comments

Question 1

Why the below code snippet provides error?

C++
#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;
}
  • A

    arr[i][j] is is not declared

  • B

    there are no any braces used inside for loop

  • C

    We have declared an array of 3 rows and 2 columns, but assigned value to 3 rows and 3 columns.

  • D

    None

Question 2

What is the size of int arr[15]; if we assume that int is 4 bytes?

  • A

    15

  • B

    11

  • C

    12

  • D

    60

Question 3

When does the ArrayIndexOutOfBoundsException occur?

  • A

    Compile time

  • B

    Run time

  • C

    Not an Exception

  • D

    None

Question 4

The first Index of the array typically starts from -----

  • A

    -1

  • B

    1

  • C

    0

  • D

    None

Question 5

When the array has free unused memory, which method can be used to free up the extra memory?

  • A

    free()

  • B

    shrinkSize()

  • C

    growSize()

  • D

    None

Question 6

Which method is used to access elements in an array?

  • A

    Sequential

  • B

    Random

  • C

    Logarithmic

  • D

    Alternative

Question 7

What is the time complexity for inserting/deleting at the beginning of the array?

  • A

    O(1)

  • B

    O(logN)

  • C

    O(NlogN)

  • D

    O(N)

Question 8

What will do the below code snippet?

C++
#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;
}
  • A

    It will create a 1d array and assign value to it.

  • B

    It will create a 1d array of size m*n and assign value to it.

  • C

    It will create a 1d dynamic array and assign value to it.

  • D

    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.

  • A

    array

  • B

    this

  • C

    super

  • D

    new

Question 10

How can we create a dynamic array in C?

  • A

    vector( )

  • B

    dynamic_array( )

  • C

    malloc()

  • D

    None

There are 30 questions to complete.

Take a part in the ongoing discussion