Home » C++ Programming » Pointers » Question
  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class N
    {
    public:
    int num1;
    void fun(int num2)
    {
    cout<< num2 << endl;
    }
    };
    int main()
    {
    int N :: *ptr1 = &N :: num1;
    void (N :: * ptr2) (int) = &N :: fun;
    N object;
    object.*ptr1 = 30;
    cout << object.*ptr1 << endl;
    (object.*ptr2) (15);
    }
    1. 30
      15
    2. 15
      30
    3. Compilation Error
    4. Runtime Error
    5. None of these
Correct Option: A

In this program, We are assigning 30 and printing it in the
main function and then for value 15, We are passing the value to class and printing it.



Your comments will be displayed only after manual approval.