What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(int i){
b = i;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show();
};
void show()
{
C c(10);
cout<<"value of b is: "<<c.b.b<<endl;
}
int main(int argc, char const *argv[])
{
show();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class B
{
int b;
public:
B(int i){
b = i;
}
};
class C
{
B b;
public:
C(int i){
b = B(i);
}
friend void show();
};
void show()
{
C c(10);
cout<<"value of b is: "<<c.b.b<<endl;
}
int main(int argc, char const *argv[])
{
show();
return 0;
}A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault
Answer: Option C

Join The Discussion