C++ interview preparation

66,662

Solution 1

Make sure you know your basic data structures and algorithms. You're more likely to be asked about that stuff than something higher up the food chain. Those are usually saved for the in-person interview.

Put another way: be solid with the fundamentals and solid with your C++ syntax. Also, knowledge of common libraries like STL and Boost couldn't hurt...but be sure you know what those libraries give you! In the end phone screens are there to cull out people who can't do the basics. Prove you can and you should move on to the next step. Good luck!

Here's some links of interview questions to check out:

Now, for completion's sake, some books:

Solution 2

I have interviewed several candidates specifically focusing on their C++ knowledge, and if there was one question that worked well to put peoples' knowledge of C++ on a gradient, it was this one:

Fix this memory leak as robustly as you can:

void doSomething()
{
Foo* pFoo = new Foo();
[do some stuff]
}
  • +1 for putting delete pFoo at the end
  • +2 for putting pFoo in a std::auto_ptr
  • +3 for knowing what RAII is - the concept, if not the acronym
  • +4 for mentioning exception-safety guarantees of the auto_ptr
  • +5 for putting pFoo in a boost:shared_ptr
  • +6 for knowing when a shared_ptr might not be freed.
  • +7 for talking about garbage collection techniques to fix circular references

This always worked to show how long someone had been working with C++. This is one datapoint you can use to tell where you are in the scale of C++ knowledge.

Edit: I would recommend someone for hire at level 3 or above.

Solution 3

  • Try some practice problems on TopCoder.

  • Check out Marshall Cline's C++ FAQ. Its a good way to learn some new stuff and bone up on the things you already know in case the decide to ask you some 'knowledge' questions as opposed to 'problem solving' questions.

Solution 4

Grab a knowledgeable friend and have them ask you some C++ programming problems that you can solve on a whiteboard. A lot of interviews will have you solve a problem on a whiteboard, and it can be disconcerting to think on your feet and write things out in front of someone if you are not used to it.

Solution 5

Something which I am starting to believe is that there is sometimes a clear divide between candidates that enjoy programming as a hobby versus those who consider it "just a day job".

Even if you don't know the answer to a specific question it is worth mentioning that normally you'd look up the answer on < your favourite resource > (eg. StackOverflow).

Based on your experience I don't think the interviewer will expect that you'll get every question right. They're most likely trying to decide if you've got "potential".

So relax and try to enjoy it!

Share:
66,662
Light_handle
Author by

Light_handle

Updated on July 09, 2022

Comments

  • Light_handle
    Light_handle almost 2 years

    I have a Phone interview coming up next with with a company which works in financial software industry. The interview is mainly going to be in C++ and problem solving and logic. Please tell me the method of preparation for this interview. I have started skimming through Thinking in C++ and brushing up the concepts. Is there any other way I can prepare?? Please help.

    Edit:

    Thank you all everyone for the advice. I just want to add that I am currently fresh out of grad school and have no previous experience. So Can you suggest some type of questions that will be asked to new grads??

    • Eric J.
      Eric J. over 14 years
      If you're going to use Google during the phone interview, get a quiet keyboard ;-) ... someone I was screening last week is the reason for that tidbit.
    • Duleb
      Duleb over 14 years
      Make sure you are sitting in a quite room and also inform your friends not to disturb you during iw.
    • Uri Lukach
      Uri Lukach about 11 years
      You can try and have a real C++ test here codelect.net/TestDetails/Cplusplus%20test%20for%20Seniors
  • Kyle Walsh
    Kyle Walsh over 14 years
    +1 for the FAQ. Def worth a second (or first, if that's your case) read before an interview!
  • Kyle Walsh
    Kyle Walsh over 14 years
    Also check out this blog post on keeping C++ declarations straight, just in case they try and trip you up with those: binglongx.spaces.live.com/blog/cns!142CBF6D49079DE8!273.entr‌​y
  • John
    John over 14 years
    +1 because I learned a few things. Thanks!
  • michelson
    michelson over 14 years
    Just out of curiosity... why would you prefer boost::shared_ptr over std::auto_ptr without more information? I would be much happier with a candidate that responded with "it depends on what is in [do some stuff]" myself.
  • UncleBens
    UncleBens over 14 years
    Indeed. If the auto_ptr would do but you wanted to avoid its pitfalls, one would use boost::scoped_ptr (or std::tr1::unique_ptr).
  • Dawn Chen
    Dawn Chen over 14 years
    std::auto_ptr is not copyable - if you try to pass it by value to another function, that function will take ownership of the pointee and, since arguments go out of scope at the end of the function call, free it then. Probably not what you had in mind. This is because auto_ptr only takes a pointer in new and guarantees deletion when out of scope. Boost's shared_ptr can be copied, as it maintains an internal reference count, so passing it by value into a function does "what you expect" by incrementing the reference count. Only when the count goes to 0 does it free the pointee.
  • Dawn Chen
    Dawn Chen over 14 years
    This is also why the scoped ptr is great - it can't be copied, period. While the auto_ptr has "transfer of ownership" copy semantics, scoped_ptr has "this code doesn't compile" copy semantics. Much harder to use unintuitively. Kudos to UncleBens for that.
  • codetaku
    codetaku about 10 years
    A couple of the sites you link have information and/or code that is just outright wrong. I'm not sure why this is the accepted or most-voted-for answer.
  • Kyle Walsh
    Kyle Walsh about 10 years
    @codetaku Well, the questions linked themselves are the value. Going through the practice of answering them will give the most benefit. That said, if you wouldn't mind pointing out the offensive content we can update the answer so other people are not led astray.
  • athos
    athos over 9 years
    @Matt in C++ 11 is the answer changed? what does it mean by "+7 for talking about garbage collection techniques to fix circular references"?