-
What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
public:
int p;
Example(int num = 0) : p(num) {};
int& operator[](int num)
{
cout << "Interview " ;
return p;
}
int operator[](int num) const
{
cout << "Mania" ;
return p;
}
};
void foo(const Example& n)
{
int Res = n[2];
}
int main()
{
Example n(7);
n[3] = 8;
int Res = n[2];
foo(n);
return 0;
}
-
- Interview Interview Mania
- Interview Mania
- Mania
- Compilation Error
- None of these
Correct Option: A
In this program, we overloading the operator[] by using subscript operator.