Bloomberg LP Interview Question for Software Engineer / Developers






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

3 cons and 3 dest for each function
Test1
Base()
Base(const Base&)
Base(const Base&)
~Base()
~Base()
~Base()

Test2
Base()
Base(const Base&)
Base(const Base&)
~Base()
~Base()
~Base()

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

3 ctor 3 dtor for each function

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

No, i think 3 constructors and destructors for test1 and 4 constructors and destructors or test2.

in test 2
1. for called for opassing an object to a funs cy value.
2. for retrurning the object by refrence(in func).
3. for initializing a
4.

- Sadaf September 29, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

in test 2
1. for called for opassing an object to a funs cy value.
2. for retrurning the object by refrence(in func).
3. for initializing a
4. for initializing b

- sadaf September 29, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can anybody explain how r 3 constructors getting called in test1 i can see only 2 one being default constructor and another copy constructor which copies by value

- destiny September 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

another one for return.

- blah October 01, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

3 Constructor and 3 destructor.
@destiny read the "temporary" topic of C++.

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

>> can anybody explain how r 3 constructors getting called in test1 i can see only 2 one being default constructor and another copy constructor which copies by value

A temporary object is created when return b; is called in func() - the return type of func is Base.

- Girish October 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please explain detail..why 3 constructor called for test1 and test2 each

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

Test1 :
1) default will be called at Base a
2) Copy constructor will be called when a is passed to func
3) Copy constructor will be called when b is returned from func

Test2 :
1) default will be called at Base a
2) Copy constructor will be called when a is passed to func
3) Copy constructor will be called when b is returned from func

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

Test1
Step-1 Default constructor will be called at Base a;
Step-2 Copy constructor will be called when passing a as formal parameter i.e func(a).
Step-3 Copy constructor will be called for return object.
Step-4 Destructor will be called for actual parameter of func.
Step-5 Now this return obj will act as nameless obj in test1() and will get destroy after line func(a) calling destructor one more time.
Step-6 Finally Destructor will be called for a.

You can see same for test2();

- Ashish October 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Not sure why test2 has only 4 constructor ...

For Base b = func(a), when the 3rd constructor is called to generated the temporary return obj, the temporary obj just get a "new name" - b - so no new copy constructor needed... right?

- DiX November 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is a compilaton error. Because,test1()/test2()doesn't exists.
And there is redfination of test().

- jeet.maninder November 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

compile and run. Then you will see for yourself. No 4 constructors for test2.

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

If you want to sound real smart in your interview, you can say that the answer to 3 depends on whether your compiler employs RVO (Return Value Optimization), which it likely thus. In this case, of the Unnamed variety.

It would be 4 otherwise (1 default and 3 copy constructors). But the compiler sees the following

Base b = func(a);
Base func(Base c){return c;}

and rewrites it as

Base b(c);

Simply put, the compiler will construct the temporary inside the space saved for object b.

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

i agree with above comment...most of the compilers do return value optimization, so that might affect the no of constructor and destructor calls

- NC-State January 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

there is no function test1 and test2

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

same number of function calls for test1 and test2
Base()
Base(const Base&)
Base(const Base&)
~Base()
~Base()
~Base()

- phenix April 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3 sets of constructors will be called for both cases, and in second case the newly created object is b, whether for first case newly created object is unnamed and is not stored in a variable.

- Sourav December 04, 2014 | 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