C++ quiz by PVS-Studio and Sergei Kushnirenko

The PVS-Studio team along with Sergei Kushnirenko prepared a quiz based on his publications about errors he found. Take the quiz, challenge your focus and coding skills while looking for errors in the C++ code. Attention! When taking the quiz, you may exclaim that some tasks are unfair. Indeed. However, please relax and approach them with humor. The quiz is just for fun.

C++ quiz by PVS-Studio and Sergei Kushnirenko

by Sergei Kushnirenko

About the quiz:

After taking the quiz, you may have questions about why this or that answer is marked as correct or incorrect. Welcome to the article: "Breaking down the C++ quiz by Sergei Kushnirenko" — here you will find answers to your questions.  Please read it only after you have puzzled over code snippets with errors and undefined behavior. Be sure — it will be more interesting.

Yes, we must replace it++ with ++it--Andrey Karpov

I decided to find out if there is practical sense in writing ++iterator instead of iterator++ when handling iterators.

Is it reasonable to use the prefix increment operator ++it instead of postfix operator it++ for iterators?

by Andrey Karpov

From the article:

I will always write ++it. I did so before but I did it "just in case". Now I can see how useful it is because I regularly launch debug versions. In general, of course, ++it has a very slight influence on the running time. But if I don't make such small optimizations in different places of the code, it will be too late and the profiler won't help me. Bottlenecks will be spread throughout the code.