C,C++ Interview Questions

I am sharing some of my interview Questions.

Updated ...


Must disagree a bit about virtual functions being slow due to "the overhead involved in searching the virtual table".
There is no searching. The virtual table is nothing more than an array of function pointers. The compiler knows at
compile time the index into the table of the virtual method being called.

I must also disagree with the opening paragraph re: friends: if it is "often useful" for one class to see the private
members of another, this is highly suggestive of a design problem. If I were writing a binary tree class, the node
class would be declared within the private section of the tree class because no user should ever need to use
an instance of the node class directly. Thus no friendship needed. (The most common use of friendship is to
overload operators, and I agree these cases are extensions of the interface. The example given prior to the last
paragraph is just bad design).

StringSingleton needlessly allocates the instance on the heap.
static StringSingleton instance;
return instance;

would have sufficed just fine.

Regarding 53) Const Data Const pointer, you plagiarized that from me. I posted that exact text here:
http://www.cplusplus.com/forum/lounge/15501/. Please remove it and provide a link to the post.

It's not clear whether this is for C or C++. The languages are subtly different.

For example, your defintion of enum is for the C Programming Language, not C++.
Topic archived. No new replies allowed.