Operators
- Which concepts does the Pre Increment use?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
call by reference
- What is the output of this program?
#include <iostream&f=gt;
using namespace std;
class Num
{
private:
int Values[15];
public:
int& operator[] (const int Val);
};
int& Num::operator[](const int Val)
{
return Values[Val];
}
int main()
{
Num Object;
Object[10] = 6;
cout << Object[10];
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are getting the values and returning it by overloading the subscript operator.
- What is the output of this program?
#include <iostream>
using namespace std;
const int SIZE = 15;
class Example
{
private:
int array[SIZE];
public:
Example()
{
register int k;
for (k = 0; k < SIZE; k++)
{
array[k] = k;
}
}
int &operator[](int k)
{
if (k > SIZE)
{
cout << " Index out of bounds" << endl;
return array[0];
}
return array[k];
}
};
int main()
{
Example Object;
cout << Object[10];
cout << Object[20];
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
In this program, We are returning the elements in the specified array location and if it is out of bound means it will return the first element.
- Pick out the correct statement.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
subscript operator has a higher precedence than the assignment operator.
- How many arguments will the subscript operator will take for overloading?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The subscript operator overload takes only one argument, but it can be of any type.