Some notes and interview tips...
http://iwannabeabird.googlepages.com/cnotes
Yup. Whoever wrote that failed the interview.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
@Dave_Sinkula
Can you please explain what you mean by that.
We should rather use relevant comments on the forum
Last edited by overbench; 07-06-2007 at 09:38 AM.
A mixture of beginner mistakes, undefined behavor, and outright flaws, it demonstrates that the one posting it has a novice level of C understanding.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Aside from the notes being pretty irrelevant for an interview, it contains at least one factual error:I could have sworn I recently read that the sign of the result of modulus is undefined by the standard. For that section, it could have simply been "Read the standard".Sign of Mod Division - Result is always the sign of first operand.
Example -14 % 3 = -2
-14 % -3 = -2
14 % -3 = 2
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
From K&R2, page 205:
The binary / operator yields the quotient, and the % operator the remainder, of the division of the first operand by the second; if the second operand is 0, the result is undefined. Otherwise, it is always true that (a/b)*b + a%b is equal to a. If both operands are non-negative, then the remainder is non-negative and smaller than the divisor; if not, it is guaranteed only that the absolute value of the remainder is smaller than the absolute value of the divisor.
Edit: I just read the following at http://www.ibm.com/developerworks/po...ry/pa-ctypes1/:
Another avenue of potential variance is handling of division. The rules for division and remainder on positive numbers are fairly well defined. C89's requirements for division and remainder on negative numbers were simply that (x/y)*y+(x%y)==x. This leaves open an ambiguity. It's obvious that -5/5 is -1. What's not obvious is how to handle -3/5. Should it be -1, with a remainder of 2, or should it be 0, with a remainder of -3? Both results have been generated by real-world processors. In C99, the decision was made to require truncation towards 0; -3/5 is 0, with a remainder of -3. This imposes additional work on some processors.
Last edited by robatino; 07-06-2007 at 11:59 AM.