Open In App

Top | MCQs on Array Data Strcuture with Answers | Question 17

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




#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;
}

(A)



It is printing the normal array

(B)



It is printing circular array rotated by 3

(C)

Syntax error

(D)

None


Answer: (B)
Explanation:

In the above program, we are just shifting the array elements by 3 circularly.

we are running loop from i = 3 to 9.

 

Hence Option (B) is correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

Article Tags :
Uncategorized