-
What is the output of this program?
#include <iostream>
using namespace std;
struct A;
struct B
{
void fun1(A*);
};
struct A
{
private:
int k;
public:
void initialize();
friend void fun2(A* , int);
friend void B :: fun1(A*);
friend struct C;
friend void fun3();
};
void A :: initialize()
{
k = 0;
}
void fun2(A* a, int k)
{
a -> k = k;
}
void B :: fun1(A * a)
{
a -> k = 35;
cout << a->k;
}
struct C
{
private:
int L;
public:
void initialize();
void fun2(A* a);
};
void C::initialize()
{
L = 45;
}
void C::fun2(A* a)
{
a -> k += L;
}
void fun3()
{
A a;
a.k = 150;
cout << a.k;
}
int main()
{
A a;
C c;
c.fun2(&a);
cout << "Data accessed";
}
-
- Data accessed
- Compilation Error
- Garbage value
- Runtime Error
- None of these
Correct Option: A
In this program, We are using the access specifiers to friend function to manipulate the values.