Skip to content

My C++ Interview Questions

March 16, 2014

Introduction

Over the years, I’ve done my share (more, it has often seemed) of interviewing candidates for C++ programming posts. During this time I’ve zeroed in on a small subset of questions I ask candidates. These have no correct answers, do not refer to manhole covers, and require no maths ability to answer. They have, however, proved effective in deciding if the candidate actually has some knowledge of C++. I present them for your delectation.

“Tell me about the copy constructor”

This is my start-off question. If people look blank when I ask it (and depressingly, lots do), then I write out the signature of the constructor for them. If they still look blank, the interview terminates – this has saved me a lot of time over the years.

What I’m looking for here is someone that knows how important copying is in C++, where it takes place, and how it can be avoided. I’d expect a decent C++ programmer to be able to talk for around 15 minutes on this, with me asking subsidiary questions.

“What are your favourite C++ books? And why are they your favourites?”

C++ is a very complex language, and to learn it thoroughly you simply have to read several good books – internet resources will not be enough. I don’t particularly care which books the candidate talks about, providing there is more than one of them, and they can come up with some convincing reasons for liking them.

“Write a program to…”

I’m not a big fan of getting candidates to write code in interviews. Often, the problem they are asked to solve is too small to prove anything, and they are unfamiliar with the setup on your specific workstations, so you are really testing how quickly they can get to grips with a toolset. However, sometimes HR or senior management will insist on a coding test. If that’s the case, then I set this problem, or something very like it, which tests the candidate’s familiarity with the C++ Standard Library in several ways:

Write a program that can be called from a command line environment like this:

myprog.bible.txt

The file bible.txt, which is provided, contains the text of the King James Bible. Your program should read this file and output the 10 most frequently occurring words, together with their frequency,  ignoring any punctuation and character case. Use the style of coding, commenting etc. that you would for a large program.

As with the other questions here, I’m not particularly interested in the details of the solution, provided they show a knowledge of Standard Library classes like strings and maps, and that the program actually works.

“What do you think the three most important features of C++11 are?”

Or similar – if the candidate has professed a knowledge of a library like Boost, I might ask about that instead. Once again, I don’t particularly care what the candidate thinks are important, only that they can talk about them articulately and knowledgably.

“If you were interviewing me, what question would you ask me”

This one is down to a guy I worked with at the now defunct Lehman Brothers (thank you, Mr James). He interviewed me, and after a couple of  questions said, “Well, you obviously know a lot more about C++ than I do, so tell me, if you were interviewing me, what questions would you ask?” I thought that was brilliant at the time, and still do – use it if you are interviewing a self-styled guru. Of course, you have to ask them why they would ask that question!

Conclusion

From the above, I think you can see that you do not have to ask candidates trick questions, or puzzles about manhole covers. Instead, you should be trying to get them to talk at length about their knowledge of the C++language and how it can and should be used.

From → c++

Leave a Comment

Leave a comment