-
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);
}
-
- 30
15 - 15
30 - Compilation Error
- Runtime Error
- None of these
- 30
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.