Home » C++ Programming » Functions » Question
  1. 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;
    }
    1. 250
    2. 295
    3. 150
    4. 395
    5. None of these
Correct Option: D

In this program, we are finding a value from the given function by using the friend for Calculate function.



Your comments will be displayed only after manual approval.