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;
} |
(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.
- Inside the loop we are printing arr[3%6] = arr[3] = ‘D’
- arr[4 % 6] = arr[4] = ‘E’
- arr[5 % 6] = arr[5] = ‘F’
- arr[6 % 6] = arr[0] = ‘A’
- arr[7 % 6] = arr[1] = ‘B’
- arr[8 % 6] = arr[2] = ‘C’
Hence Option (B) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Article Tags :
Uncategorized
Recommended Articles