Question
1.
#include
2.
using namespace std;
3.
class sample1
4.
{
5.
float i, j;
6.
};
7.
class sample2
8.
{
9.
int x, y;
10.
public:
11.
sample2 (int a, int b)
12.
{
13.
x = a;
14.
y = b;
15.
}
16.
int result()
17.
{
18.
return x + y;
19.
}
20.
};
21.
int main ()
22.
{
23.
sample1 d;
24.
sample2 * padd;
25.
padd = (sample2*) &d;
26.
cout 27.
return 0;
28.
}
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class sample1
4.
{
5.
float i, j;
6.
};
7.
class sample2
8.
{
9.
int x, y;
10.
public:
11.
sample2 (int a, int b)
12.
{
13.
x = a;
14.
y = b;
15.
}
16.
int result()
17.
{
18.
return x + y;
19.
}
20.
};
21.
int main ()
22.
{
23.
sample1 d;
24.
sample2 * padd;
25.
padd = (sample2*) &d;
26.
cout 27.
return 0;
28.
}
Answer: Option D
Was this answer helpful ?
As it assigns to a reference to an object of another incompatible type using explicit type-casting.
Output:
$ g++ con.cpp
$ a.out
14032334
Was this answer helpful ?
Submit Solution