Question
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
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
Answer: Option A
Was this answer helpful ?
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 ?
More Questions on This Topic :
Question 4.
Pick out the correct statement.
....
Submit Solution