Testing Your C Knowledge With This One Simple Quiz

One of the most exciting aspects of the C programming language — as effectively high-level assembly — is that although it’s a bit friendlier for the developer, it also adds a lot of required know-how on account of its portability across platforms and architectures. This know-how is what [Oleksandr Kaleniuk] manages to wonderfully illustrate with a simple 5-question, multiple-choice quiz on what the return value is of the provided function snippets of C code. How well do you know C?

For those who have had their run-ins with C directly (or indirectly via the support for it in languages like C++) the words ‘undefined behavior‘ (UB) are likely to induce a nervous twitch or two, along with a suspicious glance at whichever parts of reality are about to evaporate and destabilize the Universe this time. Although it is said that a proper C program is written with zero UB cases in it, in practice this can be rather tough, even before considering the other exciting ways in which a piece of code can fail to do the expected thing.

For languages other than C this is of course also a challenge, which is the reason why certification programs for e.g. avionics go out of their way to weed out such preventable issues, and only few programming languages like Ada (anything avionics, medical, etc.) and C++ (F-35 and other US DoD projects) make it into devices where failure is literally not an option.

Think You Know C? Find Out

I’ve had the fortune or misfortune of interviewing a lot of job candidates over the years. It amazes me how often someone will claim to know something, sound reasonable, but then if you quiz them on it, it becomes really obvious that they don’t know much. To flush this out, we had a three-question test that would tell you a lot. People who got the right answer were ahead of the game, of course, but even looking at how people approached the answer (right or wrong) would tell you a lot, too.

I remember one case where the answer involved casting a value. A candidate had impressed me until faced with the question to which he said (more or less): “Well, there’s this function. I think it is called ‘cast’…” I think the look on my face told him that I actually knew the answer (not surprising, since I was giving the test) and that wasn’t it.

[Oleksandr Kaleniuk] has a C quiz of only five simple questions. They reminded me of at least one of my old company’s three-question quiz. I don’t want to say too much about the character of the test because I don’t want to give away the answers, but if you think you are a C wizard, go check it out. Then come back in the comments and tell us how you did. Just try to avoid posting spoilers (although you should probably avoid the comment section until you come back).

Continue reading “Think You Know C? Find Out”