-
What is the output of this program?
#include <iostream>
using namespace std;
const int SIZE = 15;
class Example
{
private:
int array[SIZE];
public:
Example()
{
register int k;
for (k = 0; k < SIZE; k++)
{
array[k] = k;
}
}
int &operator[](int k)
{
if (k > SIZE)
{
cout << " Index out of bounds" << endl;
return array[0];
}
return array[k];
}
};
int main()
{
Example Object;
cout << Object[10];
cout << Object[20];
return 0;
}
-
- 10 Index out of bounds
0 - 15 Index out of bounds
0 - 12 Index out of bounds
0 - Compilation Error
- None of these
- 10 Index out of bounds
Correct Option: A
In this program, We are returning the elements in the specified array location and if it is out of bound means it will return the first element.