lets you leave semicolons out of your code in certain cases (it’s even in the specification
Any code samples you write should be well-presented, with a focus on functionality and documentation. That could mitigate many of the reasons that a potential employer will turn you down.
Aim for Production Quality
Although you might be tempted to code quickly in order to move onto the next part of the test, take the extra time to create solid, production-quality code that works and is well-documented.
Call Out What You’re Doing
You want your employer to know that you’re familiar with quirks, odd syntaxes, and other issues that crop up with programming languages. With that in mind, your sample code should call out exactly what you’re doing. Take C++11, for example; knowing lambda functions in this context is important, and demonstrating that for an entry-level position could take you far. In that case, it can be worth writing a comment along the lines of, “Here I'm demonstrating how to use a lambda function, although this code could also be written without a lambda function.” If you do leave comments, be prepared to discuss them further in a follow-up interview. Ultimately, you want the potential employer to say, “This person knows his or her stuff and will perform well,” and not just, “This person is cool and knows the latest fads but that's not what we're looking for.”
Of course, there will always be exceptions. Some startup might want a flashy coder, simply because they think tricks are an indicator of real skill. But if you’re applying at an established firm, playing things conservatively is likely your best option.
If you have several years of programming experience, you’ll have a lot more than just a few code samples to back up your abilities; you can point to past projects and products as examples of your virtuoso coding. But when trying to land that first or second job, it’s best to play it safe: Show that you know the basics and tools, and that you can use them to create clean code, and you’re in a good position to land the job.