Bloomberg LP Interview Question for Financial Software Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

I think your answer is correct and good enough.

- Vivi April 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Perfect Answer !
All the NON virtual methods will work assuming they work with zeroed out data elements -- data elements are set o 0 (via memset) and vtbl is totally destroyed (zeroed out) so none of the virtual functions would work.

- Aadil Farid April 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's common practice in C, to do a memset on structures, in order to initialize all member variables to some default value, usually NULL. Similarly, you can use memset to initialize class objects. But what happens if the class contains some virtual functions?

Let's take an example:

class GraphicsObject{
protected:
	char *m_pcName;
	int    m_iId;
	//etc
public:
	virtual void Draw() {}
	virtual int Area() {}
	char* Name() { return m_pcName;}
};

class Circle: public GraphicsObject{
	void Draw() { /*draw something*/ }
	int Area() { /*calculate Area*/ }
};

void main()
{
	GraphicsObject *obj = new Circle; //Create an object
	memset((void *)obj,NULL,sizeof(Circle)); //memset to 0
	obj->Name(); //Non virtual function call works fine
	obj->Draw(); //Crashes here
}

This results in a crash, because every object of a class containing virtual functions contains a pointer to the virtual function table(vtbl). This pointer is used to resolve virtual function calls, at run time and for dynamic type casting. The pointer is hidden, and is not accessible to programmers by normal means. When we do a memset, the value of this pointer also gets overwritten, which, in turn, results in a crash, if a virtual function is called.

To avoid such mysterious crashes, memset should not be used on the objects of a class with virtual functions. Instead use the default constructor or an init routine to initialize member variables.

- PP April 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Apparently Bloomberg guys have a fetish for low level C-style programming.

- Anonymous May 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I know, right. This is probably due to all the legacy codes they have to maintain.

- Anonymous May 24, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Static functions will work since they do not access data members.
About virtual functions. If a virtual function is called through the object's name (not a pointer or reference to the object) compilers can easily optimize this call so that the virtual table will not be used in run-time. Nevertheless, the behavior is undefined.

- Anonymous June 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Good Question!!

Yeah i think all class members will get initilized to 0 and the call to virtual functions will lead to some undefined behavior, most probably a crash.

- Richa Aggarwal November 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nice question.

- jais.ashish November 01, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More