Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
struct A
4.
{
5.
private:
6.
int i, j, k;
7.
public:
8.
int f();
9.
void g();
10.
};
11.
int A :: f()
12.
{
13.
return i + j + k;
14.
}
15.
void A :: g()
16.
{
17.
i = j = k = 0;
18.
}
19.
class B
20.
{
21.
int i, j, k;
22.
public:
23.
int f();
24.
void g();
25.
};
26.
int B :: f()
27.
{
28.
return i + j + k;
29.
}
30.
void B :: g()
31.
{
32.
i = j = k = 0;
33.
}
34.
int main()
35.
{
36.
A a;
37.
B b;
38.
a.f();
39.
a.g();
40.
b.f();
41.
b.g();
42.
cout
Options:
A .  50
B .  Identical results would be produced
C .  Error
D .  Runtime error
Answer: Option B

In this program, We apply the access specifiers to both the class and the structure.
Output:
$ g++ acc1.cpp
$ a.out
Identical results would be produced



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers