News for hackers. Stuff that matters.
Re:Interesting C Interview Questions and Answers by mitjak on Tuesday August 28, 2012 @05:17PM (#4445922)
I've studied most of these as part of my introductory C course in university. Are they really that interesting?
Re:Interesting C Interview Questions and Answers by throwaway54-762 on Tuesday August 28, 2012 @05:54PM (#4446076)
None of these are especially interesting C questions... Most rely on assumptions about the x86 architecture and GCC (stack grows downwards, ordering of stack variables in memory (not registers), ...).

#3 notes a warning for main not returning int, but doesn't point out that without stdlib.h, malloc() and free() will be declared implicitly with incorrect types. (Edit: this produces a warning on 4.7 GCC and Clang 3.0.)

Almost all of these questions have something wrong with them other than what the author is pointing out. I question the author's familiarity with C.

Re:Interesting C Interview Questions and Answers by peteri on Tuesday August 28, 2012 @06:04PM (#4446120)
Also the casts to (char *) from malloc suggest that the author is a C++ programmer.
Re:Interesting C Interview Questions and Answers by pfedor on Wednesday August 29, 2012 @02:41AM (#4447369)
There's a discussion in "The Practice of Programming" of which is a better style when programming in straight C. The argument for casting was that could make porting to C++ easier. The argument against it went like that (hope I'm not botching it): if the appropriate header file was not included and consequently malloc() was implicitly assumed to return an int, then without a cast assigning the return value of malloc to say char* would likely trigger a warning, but the cast will silence the warning. This could be a real bug if the convention for returning an int was different from returning a pointer (say if one was returned via a register and the other wasn't.)
Re:Interesting C Interview Questions and Answers by peteri on Wednesday August 29, 2012 @04:43AM (#4447610)
Or if you were programming on an 8086 in large memory model where int is 16 bit and a pointer is 32 bit (16 bit segment, 16 bit offset)

This makes me wonder if anyone ever did a compiler where malloc returned a segment + offset (I think that gives a 48 bit pointer) for a 386 class machine.

Re:Interesting C Interview Questions and Answers by steve-howard on Tuesday August 28, 2012 @05:23PM (#4445950)
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 by tjoff on Tuesday August 28, 2012 @05:52PM (#4446063)
Additionally there are not many classes with C at all these days.

Depends on what you are studying. While I never had any specific "learn C" courses it is by far the most used language in other courses (OS programming, parallel programming, compiler construction, network programming, micro-controllers, graphics and game programming, security courses etc.). No other language comes close (a lot of the time a C++ compiler is used but the C subset is what ultimately has been used).

Re:Interesting C Interview Questions and Answers by danielvinson on Tuesday August 28, 2012 @05:28PM (#4445971)
I took a total of 2 C classes as part of my CS degree and never learned any of these...
Re:Interesting C Interview Questions and Answers by jlgreco on Tuesday August 28, 2012 @05:42PM (#4446025)
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'.