-
What is the output of this program?
#include <iostream>
using namespace std;
const int limit = 3;
class arrayExample
{
private:
int array[limit];
public:
int& operator [](int num)
{
if (num == limit - 2)
{
int temp;
for (int k = 0; k < limit; k++)
{
if (array[num + 2] > array[num])
{
temp = array[num];
array[num] = array[num + 2];
array[num + 2] = temp;
}
}
}
return array[num];
}
};
int main()
{
arrayExample sa1;
for(int L = 0; L < limit; L++)
sa1[L] = L*10;
for(int L = 0; L < limit; L++)
{
int temp = sa1[L];
cout << "Element of " << L << " is " << temp << endl;
}
return 0;
}
-
- Element of 0 is 0
Element of 1 is 5
Element of 2 is 10 - Element of 0 is 10
Element of 1 is 0
Element of 2 is 20 - Element of 0 is 20
Element of 1 is 10
Element of 2 is 0 - Compilation Error
- None of these
- Element of 0 is 0
Correct Option: A
In this program, we are returning the array element by the multiple of 5.