i need some C/C++ test intervie questions

M

Matt Gregory

Kevin said:
As an occasional interviewer, I find I have to give a test. The first
question asks the applicant to rate their knowledge of C from 1 to 10,
where 1 is "What's C?" and 10 is "I'm Dennis Ritchie". I use this to set
my expectation of the results from the rest of the test.

The test isn't pass/fail - it's for me to get a handle on the person's
knowledge and familiarity with C. Somebody who claims to be an expert but
misses some fairly obvious questions is rated lower than somebody who
rates themselves as middling and answer the same questions the same way.

Hmmm, how do I rate myself? I would have to rate myself a 10 because
I can't think of anything offhand that I don't know about C. If I did
find something I didn't know, my rating would drop to at least 9, and
I would go look it up so then I would know it, restoring my personal
rating of 10.
 
B

Bill Reed

http://plig.org/things/beatles.html

One entry begins:

When I find my code in tons of trouble,
Friends and colleagues come to me,
Speaking words of wisdom:
"Write in C."

As the deadline fast approaches,
And bugs are all that I can see,
Somewhere, someone whispers:
"Write in C."

...and continues in much the same vein for another few verses.

A true classic. Very moving rendition. If we were at a piano bar and
you had a tip jar I'd leave you a C note.
 
M

Martin Dickopp

Denis Perelyubskiy1770880499 said:
I would argue that in 99% of the cases, this should sound an alarm. To
me, this would mean one of two things: programmer who does so either
does not know C, or uses obscure constructs.

I disagree. I would argue that in order to understand and correctly apply
the standard to a given situation, a certain amount of C knowledge is
already required.
Both of these are probably not too great. First point, for obvious
reasons, and second point, since there is a great chance that a person
reading the code would have to consult the standard to figure out what
was meant by this obscure construct

If the construct is so obscure that an experienced C programmer cannot
understand it without reading the standard, then the original author
should have documented it better. :)

Martin
 
R

Richard Heathfield

Denis said:
I started reading this book: http://makeashorterlink.com/?L1D922DC5
"How Would You Move Mount Fuji?

That's /too/ easy: I wouldn't move it. It's fine where it is.

And when the interviewer says "well, just pretend...", then you can say
"fine, I'll teleport it using my whizzy new Microsoft Teleport XP (Service
Pack 6)" and then they can say "there's no such thing as teleporting" and
then you can say "but you said to pretend!" and then they can say "well,
don't pretend /that/ much" and then you can say "I think this interview is
over" and then they can go find someone more clueless and you can go home
early.

A big time-saver all round, really.
 
R

Richard Heathfield

Denis said:
I would argue that in 99% of the cases, this should sound an alarm.
Oh?

To
me, this would mean one of two things: programmer who does so either
does not know C, or uses obscure constructs.

Without looking it up in any reference whatsoever, please tell me which way
round the middle two arguments of fread go.

If you happen to be able to recall these, great. I prefer not to trust to
memory on such occasions.

That said, I dont advocate remembering function arguments and every
function in a standard library

Aha! You see?
(although one should probably know what's
available)... but you neither do you need a standard to check for those.

Do you have a more authoritative source for the necessary information?
.... or did I misunderstand ?

I think you did. You nearly re-understood right at the end, but then you
lost it.
 
K

Kevin D. Quitt

Oh, absolutely. But does it correctly detect the opposite case, where people
have skills that they modestly understate? Your answer is of considerable
interest to shrinking violets the world over.

If they claim a low number and answer most of the questions correctly,
then I begin to suspect they may have under-rated themselves a bit. Since
nobody looks at the results but me, and since I don't have a rule for
passing and failing (because you really don't do either), it's not much of
a problem.

I would look upon a negative (self-deprecating) disparity far more
favourably than a positive (self-aggrandising) disparity.

As do I. Generally, the people who rate themselves in the 8's and 9's
have done fairly poorly. 6's and 7's seem to do the best.

Thanks. The addr in my sig block works fine. Don't worry about the answer
sheet. I'll write my own. :)

I'm sure you can. Almost all the answers to C questions come from this
group and the FAQ.
 
K

Kevin D. Quitt

Out of curiosity, would you allow the applicant to look into the C
standard? After all, I can also consult the standard while actually
programming.

I send them the test before any interview. If they do reasonably well,
then we have them in for an interview. If not, then probably not.
 
K

Kevin D. Quitt

In case I didn't make myself clear above, the answer is yes, I don't care
what resources they use.
Out of curiosity, how many people actually do this?

All the time. I don't try to remember the order of all the parameters for
the library calls. It's hard enough just remembering that some of those
routines are available.
 
M

Martin Dickopp

Richard Heathfield said:
Consult the standard during office debates? Well, it's rare. The usual
reaction to "let me just show you the bit..." is "Rich! Rich! We
***believe*** you, okay?!?!?!?!?!"

I just /hate/ it when people believe me. I don't want them to believe
me, I want them to believe the facts, even if I have stated the facts
correctly.

Therefore, when somebody asks me a question, I usually insist that he
listens to the complete answer, which often involves quoting from the
standard. ;)

Martin
 
K

Kevin D. Quitt

The problem i've had is that /any/ company that says "here, write this
test" has the test set by their best in-house programmers. of course,

That would be me. 8o)

that in itself is not a problem, the problem arises when these "best"
programmers aren't.

Well, I am - but I'm not perfect.

I did, of course, not even consider hearing an offer from the company,
especially when I pointed out the errors in every single question

Anybody who correctly points out an error (other than a deliberate one)
wins.

I'd rather not work under anyone with /that/ attitude.

Nor would I. Nor have I.

and very few want to look at the code I bring in.

I'm generally not interested in seeing an applicant's code unless there's
some special reason for it. All that's going to show me is their
programming idiom, and that can usually be changed if it's egregious. I'd
rather spend the time talking about their programming philosophy and
attitude, and trying to determine if they're going to be a good fit with
the existing crew.
 
R

Richard Heathfield

Martin said:
I just /hate/ it when people believe me. I don't want them to believe
me, I want them to believe the facts, even if I have stated the facts
correctly.

Yes, the difficulty is when you give a confident answer, they go off
happily, and then later you realise that perhaps it wasn't as clear-cut as
you thought.
Therefore, when somebody asks me a question, I usually insist that he
listens to the complete answer, which often involves quoting from the
standard. ;)

Okay, I'm listening. Here's the question: is the behaviour of this program
well-defined?

#include <stdio.h>
#include <ctype.h>

int main(void)
{
char buf[] = "hello world";
char *p = buf;
p[-1] = (toupper)(*p++); /* This is the trouble spot. */
printf("%s\n", buf);
return 0;
}

When I first saw this, I thought "no way". Then, after discussions with a
clc regular and much thumbing of the Standard, I began to come to the
conclusion that it might be okay (for suitably pedantic values of "okay",
obviously -- the code sucks, after all).

But I'm no longer certain, because... well, never mind! Is it well-defined?
If so, why? If not, why not?
 
K

Kevin Easton

Richard Heathfield said:
Martin said:
I just /hate/ it when people believe me. I don't want them to believe
me, I want them to believe the facts, even if I have stated the facts
correctly.

Yes, the difficulty is when you give a confident answer, they go off
happily, and then later you realise that perhaps it wasn't as clear-cut as
you thought.
Therefore, when somebody asks me a question, I usually insist that he
listens to the complete answer, which often involves quoting from the
standard. ;)

Okay, I'm listening. Here's the question: is the behaviour of this program
well-defined?

#include <stdio.h>
#include <ctype.h>

int main(void)
{
char buf[] = "hello world";
char *p = buf;
p[-1] = (toupper)(*p++); /* This is the trouble spot. */
printf("%s\n", buf);
return 0;
}

When I first saw this, I thought "no way". Then, after discussions with a
clc regular and much thumbing of the Standard, I began to come to the
conclusion that it might be okay (for suitably pedantic values of "okay",
obviously -- the code sucks, after all).

But I'm no longer certain, because... well, never mind! Is it well-defined?
If so, why? If not, why not?

Surely not, because the indicated line both modifies p and uses its
value for a purpose other than calculating its new value without an
intervening sequence point (the sequence point before the function call
is not necessarily intervening, because there isn't a total ordering
between the modification and use of p).

If that doesn't convince you, the above is equivalent to (by the
definition of the [] operator):

*(p - 1) = (toupper)(*p++);

....and there is nothing to prevent this ordering:

Calculate p - 1 => temp 1
Calculate p + 1 => temp 2
Fetch value pointed to by temp 2 => temp 3
Store temp 2 into p
Call toupper function with temp 3 as argument
Store result into object pointed to by temp 1

(The order of evaluation of the subexpressions making up the operands to
the = operator isn't defined).

- Kevin.
 
T

Tom Zych

pete said:
It could also be a comparitive nonscalar scale, like Moh's scale,
which is really a table. But it's incomplete.
You have to give defining examples for 2 through 9.

9. I am Henry Spencer :)

Maybe 9.5...
 
D

Denis Perelyubskiy

Ok, my mistake. We're in agreement :)

denis


Richard Heathfield, 9/4/2003 3:32 PM:
 
D

Denis Perelyubskiy

Tom Zych, 9/4/2003 5:06 PM:
Denis Perelyubskiy1770880499 wrote:




Hmm. 38 characters. Not bad, but if you want a really tiny URL,
there's http://www.tinyurl.com/ . Generally about half as long.

Ah, yes. And they have a neat bookmarklet, saving you time. Pretty
cool. :)

denis
 
R

Richard Heathfield

Kevin said:
Richard Heathfield said:
Martin said:
Consult the standard during office debates? Well, it's rare. The usual
reaction to "let me just show you the bit..." is "Rich! Rich! We
***believe*** you, okay?!?!?!?!?!"

I just /hate/ it when people believe me. I don't want them to believe
me, I want them to believe the facts, even if I have stated the facts
correctly.

Yes, the difficulty is when you give a confident answer, they go off
happily, and then later you realise that perhaps it wasn't as clear-cut
as you thought.
Therefore, when somebody asks me a question, I usually insist that he
listens to the complete answer, which often involves quoting from the
standard. ;)

Okay, I'm listening. Here's the question: is the behaviour of this
program well-defined?

#include <stdio.h>
#include <ctype.h>

int main(void)
{
char buf[] = "hello world";
char *p = buf;
p[-1] = (toupper)(*p++); /* This is the trouble spot. */
printf("%s\n", buf);
return 0;
}

When I first saw this, I thought "no way". Then, after discussions with a
clc regular and much thumbing of the Standard, I began to come to the
conclusion that it might be okay (for suitably pedantic values of "okay",
obviously -- the code sucks, after all).

But I'm no longer certain, because... well, never mind! Is it
well-defined? If so, why? If not, why not?

Surely not, because the indicated line both modifies p and uses its
value for a purpose other than calculating its new value without an
intervening sequence point (the sequence point before the function call
is not necessarily intervening, because there isn't a total ordering
between the modification and use of p).

That was quick. You're right in that the "timing" of the sequence point is
vital to the answer.
If that doesn't convince you,

This is the trouble. I was convinced twice already, in opposite directions.
:)
the above is equivalent to (by the
definition of the [] operator):

*(p - 1) = (toupper)(*p++);

...and there is nothing to prevent this ordering:

Calculate p - 1 => temp 1
Calculate p + 1 => temp 2
Fetch value pointed to by temp 2 => temp 3
Store temp 2 into p
Call toupper function with temp 3 as argument
Store result into object pointed to by temp 1

(The order of evaluation of the subexpressions making up the operands to
the = operator isn't defined).

That's basically the only way to break it, I think. I'll have another plough
through C99 next time I get a chance.
 
P

Paul Hsieh

Ditto.

If any sort of "exam" is to be part of an interview, it should be
stated beforehand.

I would expect an "exam" from any interview. When *I* am interviewed,
I generally think twice before accepting a position where I have not
been tested (because it means my coworkers were not tested, and
therefore may be of questionable skill ...)
Those of us who have been in the game for decades find this sort of
practice demeaning,

For me, its completely the opposite. In the time it takes to
interview *I* can only get a fair assessment from an interviewer if I
have been given the opportunity to demonstrate exactly where my skill
level is. If they don't test me, then they are treating me like a
checkbox. I've worked at companies that have taken both points of
view and found that my compensation was usually higher at the places
where I was more seriously scrutinized during the interview.

At two of the companies I've worked for I was *used* as an "acid test"
kind of interviewer, because I had built up a number of standard
questions so that my boss could understand my assessment.
[...] and a good indication that it is a job we don't
want anyway.

I don't know who this "we" is. I find that the length of a person's
career is not any kind of indicator of the skill level of the person I
am interviewing. Often such people have lost touch with leading edge
development ideas.
[...] Therefore, it saves time on both persons' parts.

Agreed.
 
L

LibraryUser

Kevin D. Quitt said:
.... snip ...

I doubt I'd be interviewing any of you, and if I were, it wouldn't
include the test. More along the lines of "You can't do any
better than here?".

You mean you are hiring? I can be bought. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top