C interview tips

This is a discussion on C interview tips within the C Programming forums, part of the General Programming Boards category; Some notes and interview tips... http://iwannabeabird.googlepages.com/cnotes...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    2

    C interview tips

    Some notes and interview tips...
    http://iwannabeabird.googlepages.com/cnotes

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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.*

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    2
    @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 10:38 AM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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.*

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    Aside from the notes being pretty irrelevant for an interview, it contains at least one factual error:
    Sign of Mod Division - Result is always the sign of first operand.

    Example -14 % 3 = -2

    -14 % -3 = -2

    14 % -3 = 2
    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".
    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

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    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 12:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tips for Job Interview
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 01-10-2005, 06:12 AM
  2. C++ Programming Tips
    By gflores in forum C++ Programming
    Replies: 20
    Last Post: 09-14-2004, 08:53 PM
  3. Interview coming up
    By thomashdavies in forum C++ Programming
    Replies: 2
    Last Post: 06-30-2004, 09:23 PM
  4. a list of interview questions...
    By BrianK in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 10-29-2002, 02:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21