Array Data Structure Quiz for Beginners

Last Updated : 25 Sep, 2023

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array).More on Array Data structure
 

Array Quiz for beginners

Array Quiz for beginners

Question 1

The size of the array should always be _____

Tick

Positive

Cross

Negative

Cross

whole Number

Cross

Real Number



Question 1-Explanation: 

Option A: The size of the array should always be positive to store some number of elements.
Option B: The size of the array can never be negative, as we can never have negative number of elements to store. hence we can never have the size of array as negative.
Option C: Zero is also a whole number, but we can never have zero number of elements to store. Hence, we can never have size of array as a whole number.
Option D: Real number includes - positive, negative, and zero number. so we can not have this as a size of array, as mentioned above. So we can not consider the real number for size of array.

Hence ( A ) is the correct option.

Question 2

With the help of which operator array elements can be accessed?

Cross

Parenthesis ( )

Cross

Braces { }

Tick

Subscript Operator [ ]

Cross

None of these



Question 2-Explanation: 

A Subscript operator is used to access the array element.

Eg: if we have an array, int arr[5] = {1, 2, 3, 4, 5};
To access the value, we can write:

  • First element:  arr[0],
  • Second value:  arr[1].
  • Third Value:  arr[2],
  • Fourth Value:  arr[3],
  • Fifth Value:  arr[4].

Hence Option (C) is correct. 

Question 3

Which of the following statement is correct about array?

Tick

The size of the array is fixed.

Cross

The size of the array is dynamic.

Cross

Random access is not possible in an array.

Cross

None of these



Question 3-Explanation: 

Arrays have a fixed size, once the memory is allocated to them, it cannot be increased or decreased, making it impossible to store extra data if required. An array of fixed size is referred to as a static array. 

Hence Option (A) is correct.

Question 4

Which of the following syntax correctly declares an Array in C/C++?

Cross

int geeks;

Cross

array geeks[20];

Cross

geeks{20};

Tick

int geeks[20];



Question 4-Explanation: 

Option A: This syntax is a popular way of declaring variables, and not Array.
Option B: Array is not a keyword and hence cannot be used to declare an Array
Option C: No data type is defined here. So array cannot be created using this syntax
Option D: This syntax is optimal for creating an array, as it contains a data type, variable name, and the array size.

Hence D is the correct answer.

Question 5

What is the output of the following code:

C++

#include <bits/stdc++.h>
using namespace std;

int main() {

    int arr[5] = {1, 2, 3};
  
    //Printing the value
    cout<< arr[4]<<endl;
    return 0;
}
Cross

3

Cross

Compile error

Cross

Run time error

Tick

0



Question 5-Explanation: 

If the count of elements within the “{ }” is less than the size of the array, the remaining positions are considered to be ‘0’.

In the above example, we can see that the array is declared like arr[5] ={1, 2, 3};  Now we can see that we have declared the size of the array as 5, and initialized only 3 elements, so by default the next two elements are assigned to Zero.
 

Hence Option (D) is correct.

Question 6

Which of the following statements correctly declares a two-dimensional integer array in C/C++?

Cross

arr[5 *4]

Tick

int arr[5][4];

Cross

arr[2][2]

Cross

All of these



Question 6-Explanation: 

Option A is not the correct way to declare a 2-d array in C/C++, because here data type is missing and arr[5*4] means a 1-d array of size 20.
Option B is the correct way to declare a 2-d array in C/C++. Here data type (int) is mentioned, the array name is mentioned, and also the number of rows and columns is mentioned at the time of declaration.
Option C is not the correct way to declare a 2-d array in C/C++, because the data type is missing here.

Hence Option(B) is correct.

Question 7

In an array int arr[3]={1,2,3}, what will happen if we try to access arr[4] in C/C++?

Cross

Run TIme error

Cross

3

Cross

0

Tick

Garbage Value



Question 7-Explanation: 

If you try to access arr[4], which is beyond the valid range of indices, it will result in undefined behavior. as providing garbage values.

Hence option (D) is correct.

Question 8

What is the output of the following program?

C++

#include <iostream>
using namespace std;

int main()
{

    int arr[5] = { 2, 6, 8, 13, 19 };

    // Modifing the data
    for (int i = 0; i < 5; i += 2)
        arr[i]++;
    for (int i = 0; i < 5; i++)
        cout << arr[i] << endl;

    return 0;
}
Cross

2, 6, 8, 13, 19 

Tick

3, 6, 9, 13, 20

Cross

3, 7, 9, 14, 20

Cross

None of these



Question 8-Explanation: 

In the for Loop, we are just incrementing every even_indexed  element by 1. 

int arr[5] = { 2, 6, 8, 13, 19 };

Eg:    for (int i = 0; i < 5; i += 2)
          arr[i]++;

It will increase the value of arr[0], arr[2], arr[4] by 1.

So the output will be: {3, 6, 9, 13, 20}.

Hence  (B) is the correct answer.

Question 9

What is the time complexity to insert a single element in the array?

Tick

O(1)

Cross

O(n)

Cross

O(log n)

Cross

none



Question 9-Explanation: 

The time Complexity to insert a single element in the array is O(1). Because we can access it from anywhere(means from start, from middle, from ending, or from anywhere) with the help of indices.

Eg: int arr[5] ;

Here, suppose we want to insert an element 20 at the 4th index, we can easily insert it by writing a single-line statement, and as we know a single-line statement will always take O(1) time complexity.

arr[4] = 20;

Likewise, at 3rd index:   arr[3] =30; So on.

Hence (A) is the correct option.

Question 10

What is the famous mathematical example of 2-d array?

Cross

cube

Cross

Dice

Tick

Matrix

Cross

none



Question 10-Explanation: 

Matrix is the famous mathematical example of  2-d array.  

Hence Option(C) is correct.

There are 30 questions to complete.


Share your thoughts in the comments

Similar Reads