Bloomberg LP Interview Question for Software Engineer / Developers






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

I think both of them will point to the adjacent addresses in the memory, I dont think it has anything to do with the base/ derived class concepts, as both of them are pointers pointing to the same class object so the compiler will create 2 copies (separate) of this and will allocate the corresponding addresses to the objects. Also, if we use void pointers for this instead of the class pointers then both the pointers will point to the same location.

- SID November 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I believe base and derived class concepts explain this question.
from Ronin's comments, please read:
hxxp://www.newlc.com/Multiple-Inheritance.html

- shoushou January 22, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Firstly your code wud not compile.....

so i am assuming u meant aa = &cc;
bb = &cc;

Now, to answer ur question, NO ! They would not point to the same address...

It depends on the order of inheritance.

- Adi April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To answer you second question.

You can use structure composition and function pointers...
think on those lines

struct A
{
....
}

struct B
{
....
struct A a;
}

this would get you started.

- Adi April 25, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question 1:

For floating point types, I would use something simple like Newton-Raphson approximation repeated with enough iterations to get the desired precision.

Question 2:

One can write a polymorphic function in C by allowing it to accept a general type (such as void*) and accepting a pointer to a function that operates on this general type. Specific function (sf1(), sf2(), ...) can then be provided for each type, which casts the general typed argument into specific types and operates on them.

Another clunky method is to use type fields (since C supports enumerated types and the switch/case structure).

Question 3:

Your code wouldn't compile for four reasons.
1: "Class" should be "class" (C++ is case sensitive)
2: class declarations should end with semi-colons
3: when inherited by C, B has no access specifier and therefore defaults
to a privately inherited base of C
4: "c" is an undeclared identifier (Thanks, Adi)

Assuming those three things are corrected,
(e.g. you write "class C: public A, public B { \* ... *\ };),
your code will compile, but the addresses will be off by a value dependent upon the size of an object of type A.

- Susan April 26, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I appreciate you guyz correcting my typos in question 3 (-; . Obviously the answer to the question is no, they cannot point to the same address beacuse cc inherits everything from class A and class B.So cc has a structure in memory as follows.....
| x | y | z |

where lets say aa is pointing to x and bb is pointing to y. The interviewer asked me how does this happen and why.....he wasnt satisfied by my answer that it is because of cc inheriting from class A and class B..and since aa is a pointer to class A and bb is a pointer to class B.

any suggestions....

- Sach April 26, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the reason may be that (not sure, correct me if I'm wrong): the bb is a pointer of class B, when bb = &c, the compiler will let the bb ONLY point to the region which "looks like" a object of B. However, for pointer aa, the compiler has no choice other than making it point to the same memory location with c because of the order of multiple inheritance declaration.

- Jun November 12, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just compiled and ran, Adi's answer is correct.
aa and bb point to two different addresses,


They've discussed this over at...
hxxp://www.newlc.com/Multiple-Inheritance.html

- Ronin February 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

When we inherit a class, a copy of object of parent class is kept inside the child. On the same line if we inherit a class from two parents, it will have copies of both parents.

Now when we say aa=&c; aa is a pointer of type A so it will point to the copy of A present in C, similarly thing will hold true for B and hence both will point to diff addresses

- ked February 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

agree

- Raiden March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

it should be
class C: public A, public B{
...
};
otherwise you will get the error at this line;
bb = &c;

- Anonymous September 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Siblings with 4 byte difference....

- tosha shah April 15, 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