1/24 At interviews, I've been asking, "Write a C program 'sum' that takes
two integer arguments and prints out the result. E.g., 'sum 5 12'
should print 17 to the screen." This is a gut check question, but
everyone seems to have problems with one thing or the other. Any
ideas for a better 5-10 minute written C question? Thanks.
\_Ask them to construct a simple linked list using pointers. Your
program should be a 30 second question. If people can't get that right
then you shouldn't be hiring them. Maybe it's the way you ask the
question.
\_ 30 seconds eh? you must write sloppy code.
\_ Right, no one should miss that question, so... How *exactly*
are you phrasing it?
\_ I phrase it just as I've written above. Try the question
yourself. You have 7 minutes, you explicitly do not
have a computer to test it on, and you do not have man
pages or books. Tell us whether you did it right given
these constraints.
\_ My favorite one is: write strcpy(). Tells you a lot about a
person's understanding of C.
If you want trick questions, take a look at
http://www.xcf.berkeley.edu/help-sessions/c-tricks.html -- misha.
\_ The alpha geek at our company notes:
xxxxx: but the paradigm of x[y] = *(x+y) is actually used
quite a lot... especially when you're not sure the size of
x in which case long x; x[5] is actually *(x + 5 * sizeof(x))
You learn something new every day. -- Marco
\_ Hilfinger grilled this sort of thing into us in 60c.
\_ let us hang our heads for the xcf requiem.
\_ what kind of problems do people have with this???
\_ main(int argv, int argc)
main(char **argv, int argc)
sum = argv[1] + argv[2];
x = (int) argv[1];
several other bad things
did not:
initialize sum
include any header files
I don't like my question, so I'll try the strcpy() question
next. Thanks, misha.
\_ You don't need header files to printf sum. You'll get
a compiler warning but it will print when executed.
If they can't do sum(), they sure as hell can't do a
strcpy rewrite. I suggest a series of 30 second questions
in the Hello, World or sum() realm and then give them a
shell, gcc, vi/emacs, and 30 minutes to write, and
successfully compile something more serious. After all,
they *will* have a computer once they're doing their job
on site so why deny them that during the interview? Just
another random viewpoint. BTW, I assume this is for junior
level positions.
\_ I've been in the industry for 7 years, and every time I need to use
trivial things like fgets() I still need to look up the man page.
\_ Knowing what the heck you are building is the hard part. The
programming language is the esay part.
\_ Your question is too easy. It should sum an arbitrary number of
arguments from the command line.
\_ and then compute the last digit of pi. |