Home » C++ Programming » Modifier Types » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    struct N
    {
    private:
    int p, q, s;
    public:
    int fun1();
    void fun2();
    };
    int N :: fun1()
    {
    return p + q + s;
    }
    void N :: fun2()
    {
    p = q = s = 0;
    }
    class M
    {
    int p, q, s;
    public:
    int fun1();
    void fun2();
    };
    int M :: fun1()
    {
    return p + q + s;
    }
    void M :: fun2()
    {
    p = q = s = 0;
    }
    int main()
    {
    N obj1;
    M obj2;
    obj1.fun1();
    obj1.fun2();
    obj2.fun1();
    obj2.fun2();
    cout << "Identical results...";
    }
    1. Compilation Error
    2. Runtime Error
    3. Garbage value
    4. Identical results...
    5. None of these
Correct Option: D

In this program, We apply the access specifiers to both the class and the structure.



Your comments will be displayed only after manual approval.