Bloomberg interview questions or BOA interview questions for a C++ job? Answers included too

(Last Updated On: June 15, 2010)

Bloomberg Q&A
I got phone interviewed with Bloomberg.
1)diff bet class and structure
2)syntax of copy constructor
3)why we need copy constructor?
4)why we need overloaded = operator?
5)signature of overloaded = operator for a class?
e.g. Myclass & operator =(const Myclass &)
6)why & used in return type of = operator ?
7)suppose :

class Myclass{
public:
Myclass(int a){m=a;};

private :
int m;
};

a)how will u create an array of objects of Myclass on stack?
b)how will u crete an array of objects on heap?

8)what precautions should be taken to write a class’s destructure?
9)what will u do to prevent others from creating more than one instances of ur class?
10)how will u make singleton thread safe?
10.1) what problem may occure with singleton at run time?
11)what is diff between “operator new” and “new” ?
12)what happens if new fails to allocate memory?

1. By default class has private access specifier and structure has public in C++.
2. MyClass(const MyClass &)
{
}
3. To create a copy of existing object.
4. By default = does a shallow copy so if your class has pointers to some other data type except inbuilt one then a shallow copy would be done and it may result in dangling pointers.
5. const MyClass& operator = (const MyClass &)
{
}
6. So that chaining can be possible like below
x = y = z = 10;
8. The class destructor should never throw an exception. A destructor can be called in 2 ways.One when an object goes out of scope and 2nd when stack unwinding happens.So if a destructor is called due to stack unwinding and it throws an exception then C++ unexpected is called which calles terminate which terminates the whole application.Nothing is destroyed not even local objects.
9. Make class Singleton.
10. Use Mutex to warp the code where instantiation happens.
11. Operator new allocates raw memory only.It is similar to malloc() in C.
new first allocates raw memory using operator new and then calls constructor for the class.
12. bad_alloc exception is thrown.

7a.
Myclass myclass[10]; will not work.This statement would give a compile time error as the class lacks a default constructor.

To construct the array on stack it would be done like below

int i[] = {1,2,3,4,5,6,7,8,9,10};

MyClass myClass[10] = {1,2,3,4,5,6,7,8,9,10};

—> ” Myclass *myclass = new MyClass[10]; ” here new will allocate memory and creates object as well, by calling its default constructor. During compilation, You will encounter ‘No appropriate default constructor available’ error.
Rest of the code is also error.

The correct answer to 7b is:

MyClass* mc[10];
for (int i=0; i < 10; i++) mc[i] = new MyClass(i); <--- it will call user-defined constructor here. To point#8, it is necessary declare it as "virtual" also if the destructor is called by a base pointer: class A {...}; class B: public A {...}; ... A* pA = new B(); ... delete pA; If A destructor is not virtual only A destructor is called. BOA questions 1) Type of stl containers 2) difference in composition, agregation,association. 3) Predicates 4) Deadlock and Starvation 5) Raised condition 6) Diff in Conversion ctr and explicit ctr 7) diff in has_map and map 8) explain hash_map and bucketing 9) virtaul inheritance, diamond problem 10) function adaptors 11) fucntors 12) function objects 13) in how many ways two classes A and B be related to each other. 14) diff between vector and dqueue 15) Repopulation of dqueue and its complexity. 16) types of iterators 17) how would you implement a map. 18) concept of immutability.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
This entry was posted in Misc and tagged , , , , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs