Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
private:
6.
int* i;
7.
int j;
8.
public:
9.
sample (int j);
10.
~sample ();
11.
int& operator [] (int n);
12.
};
13.
int& sample::operator [] (int n)
14.
{
15.
return i[n];
16.
}
17.
sample::sample (int j)
18.
{
19.
i = new int [j];
20.
j = j;
21.
}
22.
sample::~sample ()
23.
{
24.
delete [] i;
25.
}
26.
int main ()
27.
{
28.
sample m (5);
29.
m [0] = 25;
30.
m [1] = 20;
31.
m [2] = 15;
32.
m [3] = 10;
33.
m [4] = 5;
34.
for (int n = 0; n 35.
cout
Options:
A .  252015105
B .  510152025
C .  51015
D .  None of the mentioned
Answer: Option A

In this program, we are printing the array in the reverse order by using subscript operator.
Output:
$ g++ sub4.cpp
$ a.out
252015105



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers