Sail E0 Webinar
Question


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
Options:
A .  5
B .  4
C .  3
D .  6
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 ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers