Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class sample
4.
{
5.
public:
6.
sample(int i) : m_i(i) { }
7.
public:
8.
int operator()(int i = 0) const
9.
{
10.
return m_i + i;
11.
}
12.
operator int () const
13.
{
14.
return m_i;
15.
}
16.
private:
17.
int m_i;
18.
friend int g(const sample&);
19.
};
20.
int f(char c)
21.
{
22.
return c;
23.
}
24.
int main()
25.
{
26.
sample f(2);
27.
cout
Options:
A .  3
B .  4
C .  5
D .  None of the mentioned
Answer: Option B

In this program, we are adding its value with it itself, So only we got the output as 4.
Output:
$ g++ con1.cpp
$ a.out
4



Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers