Question
1.
#include
2.
using namespace std;
3.
class numbers
4.
{
5.
private:
6.
int m_nValues[10];
7.
public:
8.
int& operator[] (const int nValue);
9.
};
10.
int& numbers::operator[](const int nValue)
11.
{
12.
return m_nValues[nValue];
13.
}
14.
int main()
15.
{
16.
numbers N;
17.
N[5] = 4;
18.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class numbers
4.
{
5.
private:
6.
int m_nValues[10];
7.
public:
8.
int& operator[] (const int nValue);
9.
};
10.
int& numbers::operator[](const int nValue)
11.
{
12.
return m_nValues[nValue];
13.
}
14.
int main()
15.
{
16.
numbers N;
17.
N[5] = 4;
18.
cout
Answer: Option B
In this program, We are getting the values and returning it by overloading the subscript operator.
Output:
$ g++ sub1.cpp
$ a.out
4
Was this answer helpful ?
In this program, We are getting the values and returning it by overloading the subscript operator.
Output:
$ g++ sub1.cpp
$ a.out
4
Was this answer helpful ?
Submit Solution