Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

My company is currently interviewing for a developer position, and a disturbingly high number of candidates with good resumes end up being total frauds. We do have a written technical test which works fine for that purpose (it was initially designed for interns, but we found out that even candidates interviewing for senior positions failed it abysmally), but I'd like a few questions that allows us to filter out those people with a < 10 min. time investment.

I'm trying to come up with a very trivial C++ (or even just programming) question that can be easily answered on the phone. The goal is not to get tricky, or even midly complex, just to weed out the people who'd fail an "intro to programming" midterm.

So far, the best I've come up with is "Let's assume I'm an intern you're mentoring: can you explain to me, in simple terms, the difference between a vector and a list, and when I should use or the other". Any other ideas?

share|improve this question

migrated from May 6 '11 at 21:50

This question came from our site for professional and enthusiast programmers.

closed as not constructive by Mark Trapp Dec 17 '11 at 6:15

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

In order to be less C++-specific (in case a great programmer who doesn't know C++ comes along), you might want to rephrase the question to "[...] the difference between an array and a linked list [...]". – Aasmund Eldhuset May 6 '11 at 21:27
Anything that would filter out completely clueless candidates. (i.e. someone who can't answer "Can you write the code which averages this array of 10 integers". And yes, several candidates fail at that one) – Kena May 6 '11 at 21:28
The problem with the vector/list discrimination is, that a CS student could remember enough of datastructures 101 to know a good answer, but in fact have no clue how to code it/anything in c++ – sehe May 6 '11 at 21:28
"a" vector and "a" list are the same. I think you're asking about the difference between the standard library classes named vector and list, you should say that. Or else ask what class they would use if they needed a dynamically growable array with random access, and what class for a collection with O(1) insertion. – Ben Voigt May 6 '11 at 21:30

16 Answers 16

All of these should be easy to do over the phone, and would at least give you an idea whether the candidate is a waste of time or not.

If you want generic programmer questions, not c++ specific, try some of these:

  • What is polymorphism.
  • What is overriding and overloading.
  • What is heap and stack.
  • Describe the process to take a single-file hello-world source file and make it into an executable.
  • What is a hash table.
  • What is a linked list. Why would you prefer to use this rather than e.g. an array.
  • Describe the binary search algorithm
share|improve this answer
Should that be, when can/should you explicitly call the destructor? Or should that be another question... – Nim May 6 '11 at 21:39
@Nim: It's a trick question - the correct answer is that you cannot explicitly call a constructor in C++ - you can indirectly call it by constructing an object, or in base class initialization, but you cannot explicitly just call it. – Erik May 6 '11 at 21:40
@Nim: I've found that such Qs are a good test of the candidates confidence in his abilities. Someone who knows C++ very well will answer that on the spot rather than try to figure out what he's forgotten. – Erik May 6 '11 at 21:48
@Erik you may want to give the answers too... for the benefit for the potential interviewees, so that it evens out and puts @kena in the same place back ;-) – Nivas May 7 '11 at 6:10
You have to consider who you want to "weed out" here. I am a senior developer and would be insulted by being asked some of these questions. It might as well weed out you as a potential employer! – Bo Persson May 7 '11 at 7:02

Have you read about the FizzBuzz test? Over the phone you may not want to go character by character but the person should be able to describe the general algorithm to you.

Fizz Buzz Test

share|improve this answer
Is it just me, or is it really sad that applicants actually fail at this? – Maxpm May 6 '11 at 23:14
If you're going to ask a programming test, make sure to let candidates know to have a pencil and paper handy. I know it sounds stupid, but some of us have very little primary storage.. – Brendan Long May 7 '11 at 7:51
@maxpm every time this comes up, a bunch of people tell me how scarily effective this extremely simple test is at weeding out candidates. – Jeff Atwood May 7 '11 at 8:33

I've been doing a lot of interviews lately and one thing that kinda bugs me is that if a person never used dynamic_cast or explicit constructor, that doesn't necessarily make him a bad programmer. Recently I read a quote that said, "C++ is a great language if you use 80% of it, the problem is that every developer uses different 80%". Personally, just to list few things, I've implemented delegate-like behavior, extended Boost pool library using my own template meta-programming classes and recently dissected Boost MSM library almost line by line, but if you ask me if I remember of the top of my head if std::string has toupper() method, there's a 50% chance I'd fail your interview.

So I wanted to turn the interview around, leave it open ended, and let the interviewee demonstrate how deep he got into the language without me picking and choosing very specific questions. What do you guys think of this:

What is the most complex/interesting thing of C++ language you have ever used? Then I'd poke around the question to see if the person really knows whatever topic they picked.

share|improve this answer
Yes, dismissing a person based on some canned question and you run the risk of missing truly great developers. – Martin Wickman May 7 '11 at 9:59
Why would not ever using dynamic_cast bother you? Most of my C++ work was done on time-critical apps, and there's a reason you never used dynamic casts... I guess this falls into the area of "used a different 80%". – red-dirt May 7 '11 at 12:27
I guess a competent C++ programmer could answer the toupper question, even if he doesn't know: "I don't remember, but I believe no. It's just not the STL style. If there's a toupper, it would be an <algorithm> so I could plug in an ANSI string or std::string()'s begin() and end(), or also supply my own string class with iterators. That's pretty much the whole point of thins generic programming thingie. Therefore the answer is no, std::string shouldn't have an toupper function." – kizzx2 May 7 '11 at 15:33

Here are some simple ones:

  • What is passing by reference?
  • What does malloc() do?
  • What is overloading?
share|improve this answer
Not sure about your second point, I'd ask why are you using malloc() in C++ in response... – Nim May 6 '11 at 21:38
malloc is especially good if they claim to have maintained C code before or experience in embedded development. – Ben Voigt May 6 '11 at 21:39
If you asked "What does malloc do" and they said "I don't know", maybe that would be a good thing. – Mark Ransom May 6 '11 at 22:29

The questions about features of the language are apt to fall into 2 groups: those that are so esoteric that a good candidate might not know them, or those that are so simple that a candidate might cram for the interview and get them right without actually understanding them. If you want to know if someone can actually program, ask them to write a program. Obviously this is harder over the phone, so you have to make it trivially simple.

My candidate for a trivial programming question would be "Write a short code fragment to display the first 10 odd numbers". Anybody who couldn't answer that in 60 seconds wouldn't be worth wasting another 9 minutes on.

share|improve this answer
BINGO It depends on if you want to hire a language lawyer, or want to hire someone that can make you money. The best programmer I knew just barely broke the "C with classes" paradigm, but he could crank out product better than anyone. Truly one of those rare 10x more productive people. Unfortunately, for the businesses offering them, I think he would fail 98% of the C++ programming tests. Also unfortunately for them, he prefers to run his own show. – red-dirt May 7 '11 at 12:32

It is not unreasonable to expect people to have an internet connection nowadays.

During the phone screen get them to sit in front of a computer and connect to a site like collabedit then you can ask them real coding questions and see the code they produce real time.

share|improve this answer

"What does the copy constructor do" is my favorite interview question. But I think this will get closed as OT.

share|improve this answer

I've had great success in giving candidates a more substantial problem to solve (focused around design, algorithm, style and testing) before I even meet them.

Typically I get hassled by recruitment consultants who all seem to have perfect candidates for whatever I'm looking for. To them I just hand out the test, tell them the candidate needs to get me their source code in n days (i'm not too strict with the time spent), and if I like it and their CV I'll organise an interview. I think I eliminate (waving arms in the air type numbers) about 95% of fail boats that I would have otherwise spent hours (ie $$$) vetting.

This way I essentially invest zero time in useless candidates. I have an array of problems to give out and I'm now very quick at assessing them. I have even partially scripted the assessement with complexity measures and other metrics.

share|improve this answer

"What does explicit in front of a constructor declaration mean, and when would you use it?"

share|improve this answer

This is from an intro to programming course:

Assuming you had a string of characters, count how many times each letter is used and print out the least used and most used ones?

But it might not be the best question to ask for someone you are going to eventually be paying.

Just my 2c.

share|improve this answer

What is a virtual destructor and when should you use it ?

share|improve this answer

I do something similar, I generally start by asking how familiar they are with C++ and then ask a couple basic syntax questions. Starting with basic ones then moving towards more complex. The complex one tend to be less important (I don't really care if the candidate knows the answer) but how they answer the question can help you infer how comfortable with C++ they are.

  • What is a class?
  • Name a few container types (then I follow up with asking them to compair and contrast the uses)
  • What is a polymorphism
    • What is a virtual table? Where is it?
  • What is the difference between malloc + new?

I also ask about STL types and templates. I find the best questions are the ones I can come up with off the top of my head because they have come up in day to day work. Which tends to mean they will be more relevant to how well the candidate with handle the job.

share|improve this answer

These three have weeded out "experienced" developers for me recently:

What are the four explicit casts in C++ and when would you use them?

This identifies those who write C-code but think they're writing C++.

What is the difference between a struct and a class?

This identifies those who have come from C# but think that C++ is just syntactically different.

How would you convert a std::string to uppercase?

If you've ten years' experience with STL you'll know that there is no std::string::toupper() and you have probably come across std::transform().

share|improve this answer
i know std::string::toupper() and i am only programming 6 months ! – Wildling May 7 '11 at 9:09
@RYUZAKI: There is no std::string::toupper()! – Johnsyweb May 7 '11 at 9:54
Because usually I'm not working with strings, I'm working with numbers. I remember std::accumulate, std::copy, but string stuff I look up. The point is, do not assume that every C++ programmer works on the same stuff as you. – quant_dev May 8 '11 at 11:06

From my personal experience I would say dont take telephonic interviews, atleast not if the guy is in the same ciy. Ive interviewd people who are pretty good on telephonic interviews but flop miserably in a F2F . The telephone gives them a sense of security and they answer questions better than when they face the interiviewer directly.

share|improve this answer

Simple question to test critical thinking, rather than C++:

You have a list of increasing numbers given to you (of unknown size), which you can randomly access. You need to find where a particular number occurs.

What's the fastest way of finding the position of the number?

To which a good answer would likely be a description of "Gallop search" (test element 1, then element 2, then 4, 8, etc.; then binary search when you exceed the number). Obviously, they don't need to get the name right, but they'd better give you a nonlinear algorithm.

share|improve this answer

I prefer asking the following questions during a phone interview:

  • How would you swap two integers without using a third variable?
  • You have a list of phone book entries (names and numbers), what data structure would you use to store this information, assuming you only need to look up numbers based on person's name, but you don't have to add new entries to the phonebook or remove the old ones? Bonus question: how would your structure change if I said you also need to be able to insert/delete entries efficiently?
  • What is a singly linked list? What is an array? Bring examples of situations in which a linked list performs better than an array. Bring examples when array is better than a linked list. Bonus question: describe an algorithm to print the elements of a singly linked list in reverse order.
  • Name a couple of sorting algorithms you know. Describe any of them. How efficient is your algorithm of choice?

Note how I don't ask language-specific questions (e.g. name the STL containers, how do you think std::map is implemented, etc.). Those can be asked later, during the on-site interview, when the candidate proves that he's competent enough.

share|improve this answer
1. I wouldn't. I prefer to write code which is straightforward to read and performs well, and an xor swap meets neither criterion. 2. A relational database. Under the hood it's probably using a B-tree. Seriously, are you interviewing candidates for a job or for a second year of undergraduate study? – Peter Taylor May 7 '11 at 11:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.