Bloomberg LP Interview Question for Software Engineer / Developers






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

E. Becoz GetName() returns const char* . So compiler should try to type cast the person object in const char* .

- Amit March 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

D.

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

Conversion function will not have return type.. Answer is E

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

I also think E is only right, Conversion operator does not have a return type.

- divyaC April 18, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

the question is wrong...there has to be 'operator<<' which is overloaded here...
I think this should work...
char* operator<<(ostream &o,Person &p){return p.GetName();}

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

friend std::ostream& operator<< (std::ostream& o, Person const& p);

- Did you forget to add a "friend"? May 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

friend std::ostream& operator<< (std::ostream& o, Person const& p){ return o << p-> m_szName};

- To be more precise May 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

friend std::ostream& operator<< (std::ostream& o, Person const& p){ return o << p.m_szName;};

1.you cant's use -> for reference.
2.semi-colon after return

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

friend std::ostream& operator<< (std::ostream& o, Person const& p){ return o << p.m_szName;};

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

Its E.
We dont need to overload << operator. Person object has already been converted by operator const char*() conversion function.
I ran the program and its working fine.

- Richa Aggarwal November 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

E is correct answer.


Here is complete program.

class Person{
public:
Person(const char* szName)
{
m_szName = new char();

strcpy_s(m_szName,strlen(szName)+1, szName);
}
const char* GetName() const
{
return m_szName;
}

operator const char*() const { return GetName(); };

private:
char *m_szName;
};




int main(int argc, char **argv)
{
Person person("John");
std::cout <<person;
getchar();
}

output

It will print "John"

- 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