• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Array Data Structure with Answers

Question 11

A program P reads in 500 integers in the range [0..100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?
 

  • An array of 50 numbers
     

  • An array of 100 numbers
     

  • An array of 500 numbers
     

  • A dynamically allocated array of 550 numbers
     

Question 12

What will the output of the below code, be if the base address of the array is 1200?

C++
#include <iostream>
using namespace std;

int main()
{

    int arr[] = { 1, 2, 3, 4, 5 };
    cout << arr << ", " << &arr << ", " << &arr[0] << endl;
    return 0;
}
  • 1200, 1202, 1204

  • 1200 1200 1200

  • 1200, 1204, 1208

  • 1200, 1204, 1208

Question 13

What is the correct way to call the function (fun) in the below program?

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

void fun(char* arr)
{
    int i;
    unsigned int n = strlen(arr);
    for (i = 0; i < n; i++)
        cout << " " << arr[i];
}

// Driver program
int main()
{
    char arr[]
        = { 'g', 'e', 'e', 'k', 's', 'q', 'u', 'i', 'z' };
    // How to call the above function here to print the char
    // elements?

    return 0;
}
  • fun(&arr);

  • fun(*arr);

  • fun(arr)

  • None

Question 14

Let A be a matrix of size n x n. Consider the following program. What is the expected output? 

C++
void fun(int A[][N])
{
    for (int i = 0; i < N; i++)
        for (int j = i + 1; j < N; j++)
            swap(A[i][j], A[j][i]);
}
  • Matrix A

  • Diagonal Of matrix A

  • Transpose of matrix A

  • None

Question 15

What will do the following code?

C++
void fun(int arr[], int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            for (int k = i; k <= j; k++)
                cout << arr[k] << " ";

            cout << endl;
        }
    }
}
  • Prints the subsequence of the article.

  • Prints the elements of the array

  • Prints the subarray of the element.

  • None

Question 16

Which of the following is the limitation of the array?

  • elements can be accessed from anywhere.

  • The size of the array is fixed.

  • Indexing is started from Zero.

  • Memory waste if an array's elements are smaller than the size allotted to them

Question 17

Consider the below program, and what is doing this program basically?

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

void print(char a[], int n, int ind)
{
    for (int i = ind; i < n + ind; i++)
        cout << a[(i % n)] << " ";
}

int main()
{
    char a[] = { 'A', 'B', 'C', 'D', 'E', 'F' };
    int n = sizeof(a) / sizeof(a[0]);
    print(a, n, 3);
    return 0;
}
  • It is printing the normal array

  • It is printing circular array rotated by 3

  • Syntax error

  • None

Question 18

Fill in the blanks for completing the program to rotate an array by d elements.

C++
/*Function to left rotate arr[] of size n by d*/
void Rotate(int arr[], int d, int n)
{
    int p = 1;
    while (_______) {
        int last = arr[0];
        for (int i = 0; ______ i++) {
            arr[i] = arr[i + 1];
        }
        __________
        p++;
    }
}
  • p <= d , i < n - 1 , arr[n - 1] = last;

  • p < d, i < n, arr[n] = last;

  • p >=d, i >n , arr[n] =  last

  • None

Question 19

Refer the below diagram and identify the problem.

[caption width="800"] [/caption]
  • Normal traversal of the matrix.

  • Row-wise traversal of the matrix.

  • Column-wise traversal of the matrix.

  • spiral traversal of the matrix.

Question 20

Consider the below program. What is the expected output? 

C++
void fun(int arr[], int start, int end)
{
    while (start < end) {
        int temp = arr[start];
        arr[start] = arr[end];
        arr[end] = temp;
        start++;
        end--;
    }
}
  • swapping the elements pairwise

  • sorting the elements

  • Reverse an array

  • None

There are 20 questions to complete.

Last Updated :
Take a part in the ongoing discussion