Bloomberg LP Interview Question for Financial Software Developers






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

This wont compile because the operator= returns void. The overloaded operator= has to return a reference to the current object in order for the copy constructor to assign a value to z.

- srini February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The line A z = (a = b); is the only one that causes to print right?
So first it prints b and then it prints a (if A& is returned by = operator)

So the answer must be 2 3 1 2.
I do not understand how u guys got 2 2 1 1. Please explain.

- Arun March 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

in the question, constructor code is

A(int ii , int jj) :i(ii),j(ii){}

j varaible also contains i value

- siva.sai.2020 May 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The line

A(int ii , int jj) :i(ii),j(ii){}

is not clear. What is it doing?

- cirus February 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

First will work the operator=, then copy-ctor
So, 2, 2, 1, 1

- gevorgk February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

First will work the operator=, then copy-ctor
So, 2, 2, 1, 1

- gevorgk February 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't see any use of copy constructor here..

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

I tried in VC++,it can't compile with this "A z = (a = b)".Anyone has any idea what's wrong?

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

srini got the answer

- mimi February 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you make overloaded operator= return A& then, the above code will compile and you will indeed get "2211" as output, as marked by gevorg

- jairp February 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

output is 2 2 2 2

a=b writes the contents of b to a

- anonymous March 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

that assignment operator a=b only prints out the content of b and leaves a intact. so those functions are improper in every possible way.

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

arun, watchout j is initialized with ii too. i know its duh! but.. thats what they ask for.

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

What Bloomburg is going to ask...

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

Assuming they fix the copy constructor to return a self reference:

A a(1,2);
// 1 is assigned to a.i and to a.j because the constructor only uses the first parameter

A b(2,3);
// 2 is assigned to b.i and b.j
A z = (a = b);
// First, assignment operator is called, which outputs i and j of the passed in parameter (b) but does not change any values. Output is "22" and a reference to a is returned.
// Second, the copy constructor is called which only outputs the 1 and j values of the passed object (a). Output is "11"
// So the total output is "2211"

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

Assuming they fix assignment operator with A& instead of void

output will be "2222"

Here is complete program and explanation.

struct A
{
int i , j;
A(int ii , int jj) :i(ii),j(ii){}
A(const A&a)
{
cout << a.i << a.j;
}
A& operator = ( A& a)
{
cout <<a.i << a.j ;
return a;
}
};


int main(int argc, char **argv)
{
A a(1,2);
A b(2,3); ==> i and j value will be 2,2
A z = (a = b); ==> Here assignment operator will be called which will print 22. Now 'a' has b's values. then it will call copy constructor to which a object is passed which has value 22 .
}

- keyurpatel80 May 14, 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