Live data from Hacker News

Interesting C Interview Questions and Answers

thegeekstuff.com

1–10 of 41 posts

Re: Interesting C Interview Questions and Answers

#4
Question 10 is a bad question. The host environment is under no obligation to provide you with pointers to writable memory in argv. Furthermore, this is veering off from C knowledge into C trivia.

Question 12 is even worse, as the processing order is implementation defined. On my compiler, it prints out 60..40..60.

C questions should be designed to show whether or not the candidate can write robust, professional quality code, not to test esoteric knowledge that even the interviewer can't get right.

I was asked questions like these in an interview once. It was such a massive red flag to me that I went with another company (the final straw was arguing over the size of int, which he insisted was always 32 bits).

Re: Interesting C Interview Questions and Answers

#5
post #3

I've studied most of these as part of my introductory C course in university. Are they really that interesting?

Considering that tons and tons of people apply for programming jobs who don't know how to program at all, they're at least borderline useful. Additionally there are not many classes with C at all these days.

Re: Interesting C Interview Questions and Answers

#7

Question 10 is a bad question. The host environment is under no obligation to provide you with pointers to writable memory in argv. Furthermore, this is veering off from C knowledge into C trivia. Question 12 is even worse, as the processing order is implementation defined. On my compiler, it prints out 60..40..60. C questions should be designed to show whether or not the candidate can write robust, professional qual…

I think alot of these examples use esoteric or just plain "bad" C code just in order to create pits for programmers to fall into. In real life you would avoid writing code like this precisely because of these problems. The author even mentions for at least one of the examples that he had to disable or ignore compiler errors/warnings to run the code.

Sure, it can be important to know what these problems are and how to identify them if you should have to read through some terrible code written by someone else. Still, I think the author goes a bit far; it should be more important that you hire a programmer who doesn't produce this sort of code in the first place.

In the end I think there is no "best way" to technically test programmers; you're better off covering as many bases as possible with a bit of programming, a bit of documentation/explanation, some debugging, etc.

Re: Interesting C Interview Questions and Answers

#8
post #3

I've studied most of these as part of my introductory C course in university. Are they really that interesting?

I took a total of 2 C classes as part of my CS degree and never learned any of these...

If nothing else, you should be aware of the issues that using fixed size buffers with no bounds checking causes. So at least know enough to know not to use 'gets' and 'strcpy'.

Re: Interesting C Interview Questions and Answers

#9

Question 10 is a bad question. The host environment is under no obligation to provide you with pointers to writable memory in argv. Furthermore, this is veering off from C knowledge into C trivia. Question 12 is even worse, as the processing order is implementation defined. On my compiler, it prints out 60..40..60. C questions should be designed to show whether or not the candidate can write robust, professional qual…

Wow, question 12 is so bad that they completely ignore the C standard and make up rules (arguments evaluated left-to-right). There's no sequence point between function arguments.

Re: Interesting C Interview Questions and Answers

#10

Question 10 is a bad question. The host environment is under no obligation to provide you with pointers to writable memory in argv. Furthermore, this is veering off from C knowledge into C trivia. Question 12 is even worse, as the processing order is implementation defined. On my compiler, it prints out 60..40..60. C questions should be designed to show whether or not the candidate can write robust, professional qual…

Further to point one, it's under no obligation to provide you with writable memory of the size you'd like.

    strncpy(argv[0], "NewName", 7);
WTF does 7 come from, the source or the destination?
Post reply on HN