Really **wonderful** website for C interview questions!!!!!

R

Rob Somers

You people shockingly funny. You didnt mind moneys posting shit like
"Turn $6 into $15,000 in 1 month with paypal!" and when some-one like
me posted a link to a good website like

http://www.cracktheinterview.com/

all of you came on me as ton of bricks.

I don't think they are being funny - this newsgroup is not about
turning '$6 into $15,000 in 1 month with paypal!' - it is about the C
language - so if the posters don't deal with the former types of posts
when they crop up, that should come as no surprise to you. But when
obviously incorrect code (as demonstrated on the site you originally
posted) comes up, then it is the purview of the posters to respond to
such issues.

This site has a good collection
of C questions, the answers are always debetable.

The questions may be good, but from what I can see, there are a number
of answers that are definitely not good. Some have already been
demonstrated to be wrong. How about the following implementation of
the strcpy() function:

mystrcpy(char *src, char *dst)
{
while(*src++=*dst++);
}

Do you think that this is a *good* solution? Or is this one way, out
of many, and the best way is really just 'debatable'?

The C language is a
big mess if you ask me, but the sites does a decent job of helping
people attend interviews with more confidence.

I would not feel overly confident going into an interview knowing that
I could not pick out code that was just plain wrong. But then I guess
if I did not know what working code looked like, then I would not know
enough to be nervous, so then I suppose I might feel confident.


Maybe its not correct
answers, but atleast it has something than plain old forums.

Forums on the internet have become bash-him-up zones these days. And


But the point of posting the solutions is to *help* - So tell me how
does wrong code help anybody?
the last one who posts is the winner, I suppose.

Woot! I am the winner...for now at least...
 
A

Alan Balmer

You people shockingly funny. You didnt mind moneys posting shit like
"Turn $6 into $15,000 in 1 month with paypal!" and when some-one like
me posted a link to a good website like
Wrong. You see very little of that here, and when it happens, the
perpetrator is reported.
http://www.cracktheinterview.com/

all of you came on me as ton of bricks. This site has a good collection
of C questions, the answers are always debetable.

Wrong again. In most of the cases discussed, the answers are *not*
debatable. The answers given at the site were just plain wrong. You
(and the site owner) should be grateful for having received correction
and good advice from some of the leading experts in the field.
The C language is a
big mess if you ask me, but the sites does a decent job of helping
people attend interviews with more confidence. Maybe its not correct
answers, but atleast it has something than plain old forums.

So, you think people should be sent to interviews with confidence and
incorrect answers. An interesting point of view, but not a method
which is likely to get the interviewee hired.
 
R

rajanarayan2005

Yes, I do thank people who immediately jumped and replied to my post to
alert all of us that some answers were not correct. But, I did not
understand why would people flare up without reasons. I feel that
forums add more confusion to the mess already created over C and
websites can be a good alternative to forums (ofcourse, even they
should have dependable info). This site does have errors, but i am
liking the fact that someone atleast consolidated the questions. Forget
the answers, maybe it will improve over time, maybe never. But show me
another site which has such a consolidation? I havent seen any till
now.
 
C

CBFalconer

Yes, I do thank people who immediately jumped and replied to my
post to alert all of us that some answers were not correct. But,
I did not understand why would people flare up without reasons. I
feel that forums add more confusion to the mess already created
over C and websites can be a good alternative to forums (of
course, even they should have dependable info). This site does
have errors, but i am liking the fact that someone at least
consolidated the questions. Forget the answers, maybe it will
improve over time, maybe never. But show me another site which
has such a consolidation? I havent seen any till now.

I think the point is that wrong answers are not being corrected.
It is hard to tell, because you have again carelessly failed to
include the context (see my sig. below).

Misinformation is significantly worse than no information. At
least with no information the uninformed can search for proper
answers. With misinformation they have become biased, possibly
permanently. Worse, they may even pass it on to other innocent
parties. It is analogous to AIDS.
 
C

Chris Hills

Randy Howard said:
Ditto. A cynic might say howtofailaninterview.com might be a better
domain name. At least he has comment opportunity on each page, and
I sent a lot of feedback already, but it seems hardly worth the time
to continue to give him free answers so he can make more ad revenue.

That I would agree with. Why help him? I can't see why this web site
is not just a C reference. I don't like the idea it is there to give
answers for interviews.

However when I interview I shall find the questions on there web site
that have incorrect answers and use those questions. anyone using the
sight will show themselves up.

Note that he discusses inline functions, with no mention of them
being non-standard in C89.

What standard should he be working to C90 or C99?
Or, how about the list of valid main prototypes shown here:
int main()
or
int main(void)
or
int main(int argc, char *argv[])
or
int main(int argc, char *argv[], char *env[])
Oops.

Oops what?
Maybe if you're interviewing for a job writing non-standard C?

The comment with it says "//Compiler dependent, non-standard C." Which
is perfectly valid. Some systems do have an env[]

No one writes "standard-C". Be honest who does? 99% of all C written is
going to use the compiler or OS extensions and deviations.

Even you mentioned some local standard not even an ISO-C standard.

Pure standard C may make you feel self righteous but if the employer is
looking for some one who understands Sw Engineering in a particular
environment rather than a language lawyer you are stuffed.

Some one who writes perfect standard c is no use to me if they tell me

int main(void)

is sensible because in a free standing environment such as the one I use
there is nothing for main to return to. So the only real world sensible
option is

void main (void)

There is a lot more to getting it right than simply knowing the C
standard inside out.
 
C

Chris Croughton

However when I interview I shall find the questions on there web site
that have incorrect answers and use those questions. anyone using the
sight will show themselves up.

You could also use the right words (hint: 'there' and 'sight' are
homonyms for the words you probably meant).
What standard should he be working to C90 or C99?

Either or preferably both, but it should say which it is dealing with.
Or, how about the list of valid main prototypes shown here:
int main()
or
int main(void)
or
int main(int argc, char *argv[])
or
int main(int argc, char *argv[], char *env[])
Oops.

Oops what?
Maybe if you're interviewing for a job writing non-standard C?

The comment with it says "//Compiler dependent, non-standard C." Which
is perfectly valid. Some systems do have an env[]

Some systems have a single argument, some have other odd things.
Anything past the standard should say, like the standard itself does,
"other forms are possible, consult your compiler documentation" or words
to that effect. If I were doing interview questions then I might indeed
throw in an option for main with an extra parameter, just to weed out
the people who think that is normal.
No one writes "standard-C".

Trivially proved wrong.
Be honest who does?

Me. I also write standard C++ when appropriate. I also use extensions
when necessary -- which is seldom and for specific purposes, the
majority of my programming is using standard and portable C because the
code is ported to many different platforms.
99% of all C written is
going to use the compiler or OS extensions and deviations.

97.35% of statistics are made up on the spot.
Even you mentioned some local standard not even an ISO-C standard.

Pure standard C may make you feel self righteous but if the employer is
looking for some one who understands Sw Engineering in a particular
environment rather than a language lawyer you are stuffed.

No, you're not 'stuffed', you either know that environment or you don't.
Either way the website isn't going to help, because it doesn't know what
the employer might want either. It doesn't say anything about the
kReserveMem function, for a start, which is part of the environment used
by one employer I've worked for. If the employer requires someone with
intimate knowledge of their specialised environment then you are
'stuffed' if you don't have that knowledge, otherwise the employer will
expect knowledge of standard C and will expect you to train on the
differnces.
Some one who writes perfect standard c is no use to me if they tell me

int main(void)

is sensible because in a free standing environment such as the one I use
there is nothing for main to return to. So the only real world sensible
option is

void main (void)

There is a lot more to getting it right than simply knowing the C
standard inside out.

Which you obviously don't, because the C standard clearly says that in a
freestanding environment the entry point function might not even be
called main. From the C90 specification:

2.1.2.1 Freestanding environment

In a freestanding environment (in which C program execution may take
place without any benefit of an operating system), the name and type
of the function called at program startup are implementation-defined.

Or from C99:

5.1.2.1 Freestanding environment

In a freestanding environment (in which C program execution may take
place without any benefit of an operating system), the name and type
of the function called at program startup are implementation-defined.

If the interviewee doesn't know that from the Standards then indeed they
are lacking -- and since you appear to not know that it's in the
standards I'm afraid that you just failed the interview as well.

Chris C
 
R

Randy Howard

(e-mail address removed) wrote
(in article
Yes, I do thank people who immediately jumped and replied to my post to
alert all of us that some answers were not correct.
Yes.

But, I did not
understand why would people flare up without reasons.

It wasn't done without reason. There are dozens, if not
hundreds of websites (and books unfortunately) that claim to be
authoritative on C, and almost none of them actually are.
I feel that
forums add more confusion to the mess already created over C and
websites can be a good alternative to forums (ofcourse, even they
should have dependable info).

Actually the opposite is true. Here's why... forums may be
confusing at first blush, but they have the inarguable advantage
that mistakes are pounced upon and corrected almost immediately.
Websites, particularly those with admins who are either lazy,
irresponsible, or both, and do not correct errors when reported
to them (like the admin of the site in question) are the real
source of confusion about C programming, along with books by
buffoons like Schildt which teach demonstrably bad practice as
if it were fact.
This site does have errors,

It is filled with them, everything from flat out incorrect code,
things that will literally get your thrown out of an interview
from a competent technical reviewer, down to typos, spelling
errors and the like.
but i am
liking the fact that someone atleast consolidated the questions.

then you should take a look at the C FAQ by Steve Summit (GIYF),
which has both the questions and correct answers.
Forget the answers, maybe it will improve over time, maybe never.

The admin is not interesting in correcting errors on the site,
as he has informed me via email, so don't hold your breath.
But show me
another site which has such a consolidation? I havent seen any till
now.

then you haven't been paying attention.

google for "C faq summit"
 
C

Chris Hills

Chris Croughton said:
However when I interview I shall find the questions on there web site
that have incorrect answers and use those questions. anyone using the
sight will show themselves up.

You could also use the right words (hint: 'there' and 'sight' are
homonyms for the words you probably meant).
What standard should he be working to C90 or C99?

Either or preferably both, but it should say which it is dealing with.
Or, how about the list of valid main prototypes shown here:
int main()
or
int main(void)
or
int main(int argc, char *argv[])
or
int main(int argc, char *argv[], char *env[])
Oops.

Oops what?
Maybe if you're interviewing for a job writing non-standard C?

The comment with it says "//Compiler dependent, non-standard C." Which
is perfectly valid. Some systems do have an env[]

Some systems have a single argument, some have other odd things.
Anything past the standard should say, like the standard itself does,
"other forms are possible, consult your compiler documentation" or words
to that effect. If I were doing interview questions then I might indeed
throw in an option for main with an extra parameter, just to weed out
the people who think that is normal.
No one writes "standard-C".

Trivially proved wrong.
Be honest who does?

Me. I also write standard C++ when appropriate. I also use extensions
when necessary -- which is seldom and for specific purposes, the
majority of my programming is using standard and portable C because the
code is ported to many different platforms.
99% of all C written is
going to use the compiler or OS extensions and deviations.

97.35% of statistics are made up on the spot.
Even you mentioned some local standard not even an ISO-C standard.

Pure standard C may make you feel self righteous but if the employer is
looking for some one who understands Sw Engineering in a particular
environment rather than a language lawyer you are stuffed.

No, you're not 'stuffed', you either know that environment or you don't.
Either way the website isn't going to help, because it doesn't know what
the employer might want either. It doesn't say anything about the
kReserveMem function, for a start, which is part of the environment used
by one employer I've worked for. If the employer requires someone with
intimate knowledge of their specialised environment then you are
'stuffed' if you don't have that knowledge, otherwise the employer will
expect knowledge of standard C and will expect you to train on the
differnces.
Some one who writes perfect standard c is no use to me if they tell me

int main(void)

is sensible because in a free standing environment such as the one I use
there is nothing for main to return to. So the only real world sensible
option is

void main (void)

There is a lot more to getting it right than simply knowing the C
standard inside out.

Which you obviously don't, because the C standard clearly says that in a
freestanding environment the entry point function might not even be
called main.


What I said was "the only sensible real world option" I do know the
standard but there are other factors of which you are clearly ignorant.

From the C90 specification:

2.1.2.1 Freestanding environment

In a freestanding environment (in which C program execution may take
place without any benefit of an operating system), the name and type
of the function called at program startup are implementation-defined.

Or from C99:

5.1.2.1 Freestanding environment

In a freestanding environment (in which C program execution may take
place without any benefit of an operating system), the name and type
of the function called at program startup are implementation-defined.

If the interviewee doesn't know that from the Standards then indeed they
are lacking -- and since you appear to not know that it's in the
standards I'm afraid that you just failed the interview as well.

I do know what is in the standard and in fact your answer would fail the
interview. You are missing some vital information that is not part of
the standard to do with the real world. Hence my comment that knowing
the language is only part of the solution.

Being able to repeat the standard parrot fashion is of little use if you
are missing other parts of the puzzle.
 
M

Morris Dovey

Chris Hills (in (e-mail address removed)) said:

<snip>

| No one writes "standard-C". Be honest who does? 99% of all C
| written is going to use the compiler or OS extensions and
| deviations.

Hmm. On two separate occasions clients brought me on board because I
/could/ write standard-C (and in one instance had to prove it).

In the first case my assignment was to correct throughput problems in
a (hosted) stock exchange trading system.

In the second case my assignment was to design and implement LSI
circuit validation tests for a (free-standing) single-chip cable modem
system.

Both situations /did/ require extensions. Both clients were software
sophisticated and had determined that programmers who /could/ write
standard-C tended to write considerably more reliable and more
maintainable code than those who could not. Not only that, they
believed that such programmers tended to produce more code that could
be re-used.

<more snip>

| There is a lot more to getting it right than simply knowing the C
| standard inside out.

Very true - knowing the language is only the first step; and knowing
the C standard is only a part of that first step (rather like basic
literacy being a requirement for writing textbooks.)
 
S

Steve Summit

I only just came across this thread. Hoo, boy.

Randy said:
then you should take a look at the C FAQ by Steve Summit...

Oh, I really think that he (or rather, the site maintainer he's
a sockpuppet for) has taken more than just a look.

To cite but a few examples, see pages/1_1.html ("What is the
difference between the memmove() and memcpy() function?"),
and compare FAQ 11.25. Or see pages/2_14.html ("Write C code
to return a string from a function"), and compare FAQ 7.5b.
Or 2_35.html ("Write a program to check if a given year is a
leap year or not?"), and compare FAQ 20.32. Or pages/6_1.html
("What is a NULL pointer? How is it different from an unitialized
pointer? How is a NULL pointer defined?"), and compare FAQ 5.1
and 5.13. (For extra credit, find the old version of the FAQ
list where I misspelled "uninitialized" in the same way.)

Or see pages/7_6.html ("How to declare an array of N pointers to
functions returning pointers to functions returning pointers to
characters?"), and compare FAQ 1.21, and ponder how the reader
is supposed to learn how to understand or construct complex
declarations based on just the one example, devoid of any
explanation. (Also ponder the second "answer", which it is said
"seems to be correct", although I can't make heads or tails out
of it, and it elicits a syntax error from cdecl.) Or see
7_7.html ("Can we declare a function that can return a pointer
to a function of the same type?"), and compare the (old) FAQ 1.22.
Or see pages/8_1.html ("Whats a sequence point?"), and compare
FAQ 3.8.

Finally, see pages/1_3.html ("Write your own printf() function in C").
I was surprised to see that question, since even a stripped-down
printf is not necessarily trivial to write. But sure enough,
the proffered code looks eerily familiar to me. If you have the
book-length version of the FAQ list, you can compare it to
question 15.4. The differences are also intriguing, because once
upon a time I had written that code using an auxiliary function
named convert(), not baseconv(). I don't remember where I might
have posted that version, but evidently I did. (Note also the
curious parameterless function definition "convert(unsigned, int)".)

Most of the material lifted from the FAQ list is paraphrased,
not copied outright, and I certainly don't insist on credit, but
it would have been nice to provide at least a link *somewhere*.
Ah, well.

Steve Summit
(e-mail address removed)
 
S

Steve Summit

Where do these people come from? And why is it that the louder
they promote themselves, the shoddier they are deep inside?
(I know, I know, don't answer that.) And why is it that they all
subconsciously adopt exactly the same caps-laden snake-oil-salesman
diction? I mean, take a look at the http://www.cracktheinterview.com/
home page...

A few more errors, all rather amusing:

pages/1_0.html ("write your own atoi function"): "#include <stdioi.h>"
So much for testing the code!

pages/1_8.html ("Write C programs to implement the toupper()
and the isupper() functions") contains the curious advice
"Its important to know that the upper and lower case alphabets
have corresponding integer values. A-Z - 65-90; a-z - 97-122."
But in fact C programmers rarely if ever need to know these
values, because the compiler is happy to interpolate them when
the programmer uses character constants such as 'A' and 'Z'
(as the code here, in fact, properly does!). Now, there's the
remaining issue of assuming that the letters are contiguous
in the character set, although that's almost a nonissue today
(when's the last time any of used an EBCDIC machine?), and at
any rate there's some more code farther down which skirts the
issue by using a "correspondance" table. (That code is rather
sophisticated, in marked contrast to much of the other code on
the site.)

pages/2_0.html ("Write a C program to swap two variables without
using a temporary variable"): Astonishingly, the answer is mostly
correct and hits all the important points -- the author has been
paying attention (perhaps to FAQ's 3.3b, 10.3, and 20.15c).
But where it says "One solution to this problem is to check if
the numbers to be swapped are already equal to each other" and
shows code containing the extra test "if(*a!=*b)", it would be
more direct to discover whether the *pointers* are equal to each
other, i.e. "if(a != b)". (Also the code here is still using
the unsafe overcompressed multi-side-effect representation, even
though it was correctly argued just above that it's nonportable.)

pages/1_1.html ("Implement the memmove() function"). I'm afraid
comp.lang.c is probably to blame for some unfortunate code here.
There was an earlier criticism of a nonportable pointer comparison
on what I presume was an earlier version of this page. The test
now involves

// Check if there is an overlap or not.
while (p2 != from && --p2 != to);

which, though it may be portable, is shockingly inefficient;
no one would use code like this in practice. One of the reasons
that memmove is specified as a standard library function is so
that implementations can use whatever less-than-strictly portable
(but maximally efficient) overlap test works on their platform.
So the earlier criticism was misguided, because I'm sure that
the "nonportable" comparison *is* how memmove is typically
implemented in practice.

Randy said:
It wasn't done without reason. There are dozens, if not
hundreds of websites (and books unfortunately) that claim to be
authoritative on C, and almost none of them actually are.

Indeed. rajanarayan, you really can't complain about people
"flaring up" at you. You spammed a bunch of newsgroups with
hype-filled messages promoting this site, hoping lots of people
would visit. Guess what, they did, and they're letting it be
known what they found! You wanted publicity, you got it!
The site has a bunch of (one-sided and probably fabricated)
endorsements on its "guest book"; the open forum of comp.lang.c
is simply providing an opposing viewpoint.

Steve Summit
(e-mail address removed)
 
R

Richard Heathfield

Steve said:
Where do these people come from? And why is it that the louder
they promote themselves, the shoddier they are deep inside?
(I know, I know, don't answer that.) And why is it that they all
subconsciously adopt exactly the same caps-laden snake-oil-salesman
diction? I mean, take a look at the http://www.cracktheinterview.com/
home page...

I SEE WHA ... ahem.

I see what you mean. Partly it's that such people tend to value form over
content, style over substance, coolness over correctness - without ever
realising that what they have is not well-formed, or stylish, or cool.
A few more errors, all rather amusing:

And when you correct the errors, they take your correction, paste it on the
site (almost certainly without understanding it), and write UPDATED!!! on
the link, which makes the naive reader think the Web site maintainer has
done something wonderful.

Extra brownie points for anyone who can get them to update their site
unwittingly with a "correction" which is in fact incorrect in an amusing
way.
 
P

pete

Steve Summit wrote:
pages/1_1.html ("Implement the memmove() function"). I'm afraid
comp.lang.c is probably to blame for some unfortunate code here.
There was an earlier criticism of a nonportable pointer comparison
on what I presume was an earlier version of this page. The test
now involves

// Check if there is an overlap or not.
while (p2 != from && --p2 != to);

which, though it may be portable, is shockingly inefficient;
no one would use code like this in practice.

I like the shockingly inefficient approach.
I think that the emphasis should be on getting it correct.
What other reason can there be for implementing memmove
in portable C, except as an academic exercise?
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top