Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Recently I went to an interview for a C development position. Instead of asking me questions, they just gave me 20 code snippets to find out two logical errors on each one. I just couldn't complete all of the 20 since it took me time to go through each of these code snippets.

My question is: Is this the right way to judge a candidate? If yes, how can I improve over my error detection skills so that I don't need to waste a lot of time in the next interview? If possible, please, suggest me some links where I could find lots of samples of such questions (mainly in C).

Thanks and regards, Maddy

share|improve this question

migrated from stackoverflow.com Jan 10 '11 at 15:03

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

Its purely dependent on interviewer how they judge their candidate. We can't do anything for that. To improve you error detection answer is as usual "Practice and more practice". To find example just google "Interview question for C" or "Practical interview question for C". –  Harry Joy Jan 10 '11 at 8:51
@Harry...I really agree with that.Now the main problem lies in the fact that these questions are just extracts of some code related to that company where we never have any idea what is it actually about.i really dont think this is the perfect way to judge any candidate within a certain time limit. –  Maddy Jan 10 '11 at 8:53
That sounds pretty absurd. If the only important thing about an applicant to that particular company is that they can identify and debug logical errors as quickly as possible, that might be a good indication of what your job will be. I'm not sure you want to work there. Debugging skills are important, but writing code without logical errors in the first place seems like a good approach, too. –  Cody Gray Jan 10 '11 at 8:54
@Maddy its normal. as for example If you are going for interview for "Java developer" then you should at least know the basic knowledge of Java coding. and company will surely give you some Java code snippet to handle to test how much you know about Java. So as per i think it is normal to ask code snippets in interview. It helps company to know how much knowledge a candidate have in which he is applying. –  Harry Joy Jan 10 '11 at 8:59
I had a similar experience (one snippet each, in 3 different languages). The code was totally out of context. But the interviewer just wanted to know how I analyse the code and figure out what it does. (Later, he, "out of curiosity" asked me whether I could say some potential tool/application where it could be used). So, I guess it happens that way at some places. (well, he had more snippets, but I think he stopped when he was happy with me, for I got the offer soon) –  ThisIsMeMoony Jan 10 '11 at 9:04

3 Answers 3

Spotting and fixing errors is obviously an important part of a developer day-to-day, but shouldn't be used alone for the purpose of technical evaluation.

Fixing errors (or bugs) can be hard and tricky, but we can split them in 2 main types:

  1. Compile time
  2. Runtime

If you have a solid understanding of the language in question, you should be able to quickly figure out most of the compile time errors, mainly in a small snippet.

Runtime errors are generally trickier, but in C you should be able to spot a simple index out of bound, a NULL (or dangling) pointer dereference, double frees, infinite loops, wrong conditionals, and so on. Of course, here we're not talking about gigantic complex code. Even though snippets can be extremely complex, I don't expect it in a interview. Mostly because I would reject any employer that prefers small-complex over simple-readable code (except when it comes to performance).

The best way to get better is practicing. I learn something nearly every day at StackOverflow, and I think the time I invested here has been reciprocated. As an example, I recently started querying the standard because it's cited so many times in questions & answers that it became impossible to get involved in some discussions without a solid reference to back me up.

To conclude, I seriously doubt this "interview method" is effective, unless the employer looks for someone to fix bugs exclusively. Otherwise, restricting the technical evaluation to such test means the employer is ignoring more important skills.

share|improve this answer
@jweyrich...Thanks for that answer.The main bottleneck is the time limit which they give for solving these 20 question with complexity increasing with each question.I really feel that the best way to find errors is something like you compile and then find out the issue. –  Maddy Jan 10 '11 at 9:55
@Maddy: the time limit is generally used to evaluate how the candidate work under pressure, so don't feel bad. More important than completing 20 tasks, is to accomplish them correctly - otherwise they'll need a new round of hirings to fix your bugs. –  jweyrich Jan 10 '11 at 10:02

do not discount these type of interview questions. the skill being tested in 'code comprehension' questions is the ability to do a mental dry run of the code. this skill demonstrates greater feel for the language. candidates who possess this ability will write code that works the first time, and will be able to do it faster. they will also be able to copy paste code from other projects and modify it faster.

the way to improve this skill is to read more code and try to understand what it does.

you can start with the smaller open source c libraries.

another way to improve this ability is to solve computer programming problems in at least 5 different ways.

yet another way is to ensure your code is correct before compiling and executing. to make sure you are doing all the work, either you use a simple text editor, or you turn off all the syntax highlighting/intellisense stuff while you are programming.

share|improve this answer

Yes, but not completely.

You should judge a candidate on technical merits, but not solely. Having them write code (or use code) during the interview is essential in my opinion, but at the same time you need to look at much more then that. Are they a good fit for the team? Do they have the experience necessary to work without instruction? Do they interact well with others?

share|improve this answer
Sorry but a clear -1. Finding errors in code snippets without context and even without a computer is a dumb thing to do. Do some brief pair programming instead. –  user8685 Jan 10 '11 at 15:14
@Developer Art: I focused on it's a good way to measure some aspects of technical merit, not as a whole interview. –  Josh K Jan 10 '11 at 15:41
Attempting to debug code without a compiler seems like a tedious, academic exercise at best. Obviously, an experienced programmer will/should be able to look at a snippet of code and see obvious logical errors, but there's as much point to requiring them to demonstrate this as there is for an engineer to do long division in a job interview. Mix in speed as a criterion, and you've got a really poor way of evaluating candidates. –  Cody Gray Jan 11 '11 at 5:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.