Tuesday, April 14, 2009

New C++ questions....

Surprisingly the number of interview questions posts have increased since I am appearing for a number of interviews..... but surely this helps me and I hope that it will help some other people too.


1. Tell me the fundamentals of OOPS.

--> Encapsulation, Inheritance, Polymorphism. Define them.

Surprisingly I was asked that I missed abstraction. I believe it is a generic term for encapsulation.


2. Implementation of polymorphism in recent projects...

Implemented the Logger class to log all the install scripts as well as other database related scripts.


3. What kind of polymorphism did you implement in the recent projects?

--> Run time polymorphism.


4. Explain operator overloading.


5. What is a virtual funtion?


6. What are memory leaks?


7. What is a function pointer?


8. What is a VPT (Virtual Pointer Table)?


--> The virtual table is actually quite simple, though it’s a little complex to describe in words. First, every class that uses virtual functions (or is derived from a class that uses virtual functions) is given it’s own virtual table. This table is simply a static array that the compiler sets up at compile time. A virtual table contains one entry for each virtual function that can be called by objects of the class. Each entry in this table is simply a function pointer that points to the most-derived function accessible by that class.


9. What is a smart pointer?


-->Smart pointers are objects which store pointers to dynamically allocated (heap) objects. They behave much like built-in C++ pointers except that they automatically delete the object pointed to at the appropriate time. Smart pointers are particularly useful in the face of exceptions as they ensure proper destruction of dynamically allocated objects. They can also be used to keep track of dynamically allocated objects shared by multiple owners.

No comments: