Goldman Sachs Interview Question for Software Analysts


Country: United States
Interview Type: In-Person




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

Please correct me if I'm wrong ...

There is a single static v-table per class and all objects of a polymorphic class share it.
However , the compiler adds a virtual pointer to each object of this polymorphic class .
and inside the constructor initializes it to point to the v-table .... So I believe Virtual pointers(v-ptrs) will be 50 per base class object and 50 per derived class object .....

- Anonymous August 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

very first answer is correct ! Each class having virtual function in it, will have single virtual table. But each object of such class will have virtual pointer in it.

so base 50 objects will have 50 virtual pointers (one per each)
same for derive.

Just for example.

class base
{
public:

virtual fun1()
{
}
};

class derive : public base
{
public:
virtual fun2()
{

}
};

int main()
{
derive b1, b2;
printf("%d %d\n", sizeof(b1) , sizeof(b2));

derive d1, d2;
printf("%d %d\n", sizeof(d1) , sizeof(d2));
}
you will get answer :- 4,4,4,4,

here 4 is the virtual_pointers size.

- pranavTank August 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't know how compilers are implemented. To the best of my knowledge, all instances of Derived class can share the same virtual pointers.

- Fei Jiang August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Virtual pointers are implemented by virtual table. For each derived class, there will be one virtual table. So this single table will be applicable for all objects created from the same derived class.

virtual table not related to objects, it is related to derived class.

- Vin August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is virtual pointer ? plz help

- Say August 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As per the problem definition , It's polymorphic class. There will be single virtual table for base and derived class for all n number of object.
Kindly completed your question.

- san August 16, 2013 | 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