Question
1.
#include
2.
using namespace std;
3.
const int limit = 4;
4.
class safearray
5.
{
6.
private:
7.
int arr[limit];
8.
public:
9.
int& operator [](int n)
10.
{
11.
if (n == limit - 1)
12.
{
13.
int temp;
14.
for (int i = 0; i 15.
{
16.
if (arr[n + 1] > arr[n])
17.
{
18.
temp = arr[n];
19.
arr[n] = arr[n + 1];
20.
arr[n + 1] = temp;
21.
}
22.
}
23.
}
24.
return arr[n];
25.
}
26.
};
27.
int main()
28.
{
29.
safearray sa1;
30.
for(int j = 0; j 31.
sa1[j] = j*10;
32.
for(int j = 0; j 33.
{
34.
int temp = sa1[j];
35.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
const int limit = 4;
4.
class safearray
5.
{
6.
private:
7.
int arr[limit];
8.
public:
9.
int& operator [](int n)
10.
{
11.
if (n == limit - 1)
12.
{
13.
int temp;
14.
for (int i = 0; i 15.
{
16.
if (arr[n + 1] > arr[n])
17.
{
18.
temp = arr[n];
19.
arr[n] = arr[n + 1];
20.
arr[n + 1] = temp;
21.
}
22.
}
23.
}
24.
return arr[n];
25.
}
26.
};
27.
int main()
28.
{
29.
safearray sa1;
30.
for(int j = 0; j 31.
sa1[j] = j*10;
32.
for(int j = 0; j 33.
{
34.
int temp = sa1[j];
35.
cout
Answer: Option A
Was this answer helpful ?
In this program, we are returning the array element by the multiple of 10.
Output:
$ g++ sub2.cpp
$ a.out
0102030
Was this answer helpful ?
More Questions on This Topic :
Question 3.
Pick out the correct statement.
....
Submit Solution