Interview questions
Orion Innovations
class A
{
public:
A()
{
printf("A def ctor\n");
}
~A()
{
printf("~A def dector\n");
}
char ac;
};
static A statObject;
int main()
{
printf("Size of A = %d\n", sizeof(A));
printf("main()\n");
}
//=====================
//output: here
//
A def ctor
Size of A = 1
main()
~A def dector
struct A
{
A() { cout << "A" << endl; }
~A() { cout << "~A" << endl; }
};
struct B
{
B() { cout << "B" << endl; }
~B() { cout << "~B" << endl; }
};
struct D
{
D( D& d ) { cout << "&D" << endl; }
D() { cout << "D" << endl; }
~D() { cout << "~D" << endl; }
};
struct C : B
{
A a;
C()
{
D d;
throw d;
cout << "C" << endl;
}
~C() { cout << "~C" << endl; }
};
int _tmain(int argc, _TCHAR* argv[])
{
try
{
C c;
}
catch ( D& d )
{
cout << "hello world" << endl;
}
return 0;
}
class A
{
public:
A()
{
printf("A def ctor\n");
}
~A()
{
printf("~A de ctor\n");
}
};
class Base
{
public:
Base()
{
printf("Base ctor\n");
}
virtual ~Base()
{
printf("Base dector\n");
}
A m_A;
};
class Derived : public Base
{
public:
Derived(): Base()
{
printf("Derived ctor\n");
}
~Derived()
{
printf("Derived dector\n");
}
};
void main()
{
// Type the output of this progra
Base * pBase = (Base *)malloc(sizeof(Derived));
pBase->Derived();
free(pBase);
}
//=====================
//output:
//A def ctor
//Base ctor
//Derived ctor
Comments
Post a Comment