Friday 4 January 2013

Matt Test

My erstwhile colleague Mr. Laver is sitting a Microsoft Certification test on Thursday, which he needs no luck at all to pass. While we were discussing a C bug problem, he introduced me to IDEOne, an online source code editor which has the novel feature of being able to embed the code into your own web site:


So... why does this code compile and run but the length function only produces zero no matter what string is input?

3 comments:

  1. The for loop doesn't have a semi-colon at the end. This means that the return is executed on the first iteration of the for (and terminating both the form and the function), no matter what the length of the string. The variable index is equal to zero at this point so the function will always return zero.

    ReplyDelete
  2. Replies
    1. It'll be a walk in the park. I'd wear your nicest brown trousers, though.

      Delete