Bloomberg LP Interview Question
Software Engineer / DevelopersRe: Question 4
It depends whether depth refers to the number of links or the number of nodes on paths from root to leaf. If depth(T) := numLinks(path(root(T), maxleaf(T)) = 10, then it is 2^10 or 1024.
Otherwise, if depth(T) := numNodes(path(root(T), maxleaf(T)) = 10, it is 2^9 or 512.
Re: Question 5
A void pointer can easily be converted to an integer pointer ([unsigned/signed] [long/short] int*) through static casting.
e.g. void* vp = malloc(100);
int* ip = (int*) vp;
In C++, C-style casting can be avoided, and so the following is preferred:
int* ip = static_cast<int*>(vp);
Sorry my bad....
Question 3 again....
class example
{
int bytes;
virtual functionName{ };
}
How much memory will this class take?
I was asked this question after talking about virtual tables....
The answer is that the int would require 4 bytes and since the virtual function contains a pointer to the virtual table for this class, it would require another 4 bytes for storage of this pointer plus some bookkeeping information.
The VTBL pointer you're refering to is named something like vptr in C++. Every abstract data type object(class containing at least 1 v.f.) contains it in memory. I'm not sure if this is what you meant. Seemed like, based on your explanation, that a vptr is created for every virtual func.
I will presume you meant something like this.
class example
{
int bytes;
virtual void functionName();
};
int's generally require 4 bytes, on most machines. However, some legacy systems still only allocate 2 bytes for an int. C++ only requires that sizeof(char) <= sizeof(int), so theoretically, implementations could vary this quite a bit.
Otherwise, it seems okay.
Re: Question 3
- Susan April 22, 2006If this is C++, the function definition, as written, does not appear as though it would even compile. There are no argument lists, functionName has no return type, is defined improperly (function blocks are not terminated by semi-colons), and functions must be defined outside all other functions.
Why would they ask something like this?