You should take as much care with the preparation of sample code as you do with your resume. The purpose is to sell your skills to the potential employer.
As an interviewer what I looked for was code that made sense and would work. I looked for code that showed a level of complexity consistent with the job I was hiring for. A code sample for a senior devloper would be expected to be more complex than one from a junior developer. I looked for the abilty to adhere to a consistent style (it didn't have to be the style we preferred, but should be internally consistent). I was looking for evidence of a cowboy coder who didn't care how maintainable the code was (something that would not be a good thing). I wanted the code to be something that shows you can solve the types of problems I have.
But most of all I was looking for the code to be something the person could explain to me. You would be amazed at how many times I have gotten a code sample when that person could not explain what it did or how it did it. And if it was something that you are personally proud of and excited to talk about, that helps too.
Another thing interviewers are looking at when getting code samples is your judgement. Even if you don't have an NDA, we don't want to see code that clearly identifies the company it came from. We want you to tell us that you have specifically modified the code to avoid an NDA and it is not exactly the same as what was actually implemented. Or we want you to tell us it came from a personal project with a link to the the whole project.
We want to see if you gave us code that relates to the job we are hiring for or is at least at the right level of complexity (this is part of the judgement test, have you thought about what kind of code we would want to see). If I'm hiring you to do backend database work, I would expect to see database code. If I'm hiring you to create web sites, I would expect to see some front end code. If I'm hiring to do embedded code in hardware that is the type of code sample I want. If I'm hiring to do games programming, then a game program or at least something showing that you can handle the math involved is what I want to see. I also want to see the solution to an interesting problem.
It's true that most professional code is under an NDA, however it is possible take such code and make it so that the it does something similar to what the orginal code did but is not identifiable to a specific company or process. I believe the proessional who wants a job should have taken the time to create a portfolio of his or her work in such a way as to make it not company-related. The code can be from a personal project or from something that the person rewrote at home to be not under the NDA using concepts similar to things he did at work. Rewriting it in a different language than the one you used at work would be extra impressive. A code sample doesn't have to be a complete application as the interviewer is not going to go through thousands of lines of code. But don't make it so short that it doesn't show your skill level either.
Above all don't make the code sample sloppy or buggy. Handle errors, be consistent in your naming practices, use good design patterns, avoid antipatterns, etc.