Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
const int limit = 4;
4.
class safearray
5.
{
6.
private:
7.
int arr[limit];
8.
public:
9.
int& operator [](int n)
10.
{
11.
if (n == limit - 1)
12.
{
13.
int temp;
14.
for (int i = 0; i 15.
{
16.
if (arr[n + 1] > arr[n])
17.
{
18.
temp = arr[n];
19.
arr[n] = arr[n + 1];
20.
arr[n + 1] = temp;
21.
}
22.
}
23.
}
24.
return arr[n];
25.
}
26.
};
27.
int main()
28.
{
29.
safearray sa1;
30.
for(int j = 0; j 31.
sa1[j] = j*10;
32.
for(int j = 0; j 33.
{
34.
int temp = sa1[j];
35.
cout
Options:
A .  0102030
B .  1020300
C .  3020100
D .  error
Answer: Option A

In this program, we are returning the array element by the multiple of 10.
Output:
$ g++ sub2.cpp
$ a.out
0102030



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers