Functions
- What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
int value1, value2, value3;
public:
int get()
{
value1 = 100;
value2 = 350;
value3 = 450;
}
friend float Average(Example obj);
};
float Average(Example obj)
{
return float(obj.value1 + obj.value2 + obj.value3) / 3;
}
int main()
{
Example object;
object.get();
cout << Average(object);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are finding the Average value by declaring the function Average as a friend of class base.
- What is the output of this program?
#include <iostream>
using namespace std;
class Example
{
private:
int p, q;
public:
void test()
{
p = 150;
q = 250;
}
friend int Calculate(Example Exmp1);
};
int Calculate(Example Exmp1)
{
return int(Exmp1.p + Exmp1.q) - 5;
}
int main()
{
Example obj;
obj.test();
cout << Calculate(obj);
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
In this program, we are finding a value from the given function by using the friend for Calculate function.
- What is the use of function call operator?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
overloading the objects
- Pick out the correct statement.
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
virtual functions does not give the ability to rewrite a templated function
- What will happen when the function call operator is overloaded?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
It will modifies how the operator is to be interpreted when applied to objects of a given type.