Sail E0 Webinar
Question


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.
}
Options:
A .  20
B .  runtime error
C .  random number
D .  c or b
Answer: Option D

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 ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers