# Questions and Answers

Source of questions

# Question 2: Friend of a class

#include <iostream>
using namespace std;

class Base {
    int x;
public:
    Base(int x = 0) :x{ x } {}
    friend int main();
};


int main()
{
    Base b(10);
    cout << b.x << endl;
    return 0;
}



// A. 10
// B. Compile Time Error
// C. Run Time Error
// D. 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Answer: A. 10

Dispite int x be private on the Base class, the class has made int main() a friend, so it can access the int x variable.