Home » C++ Programming » Functions » Question
  1. 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;
    }
    1. 100
    2. 200
    3. 300
    4. Compilation Error
    5. None of these
Correct Option: C

In this program, We are finding the Average value by declaring the function Average as a friend of class base.



Your comments will be displayed only after manual approval.