3 ms·
"Curated" seems rather strong. One of the C++ lists has some let's-trip-you-up-on-trivia questions, with bad answers to boot: > 1. Explain mutable and volatile
by jcranmer 8y ago
"Curated" seems rather strong. One of the C++ lists has some let's-trip-you-up-on-trivia questions, with bad answers to boot:
> 1. Explain mutable and volatile keywords.
> Volatile keywords are designed to prevent the writer from applying optimisations on objects over which he or she has no control. Any objects that are declared as volatile are just omitted from optimisation to prevent values being changed by coding outside the scope of the original code.
Volatile is a keyword which tells the compiler to not optimize away loads or stores to the relevant memory location (note that volatile is actually a property of memory accesses, not variables, so there's lots of fun corner cases such as volatile bitfields). Actually, strictly speaking, it was originally meant to tell the compiler that the variable was being used to access memory-mapped I/O registers, but it has been shoe-horned to serve other deoptimization uses as well.
> 5. When would you use virtual inheritance?
When you want to find bugs in your compiler. :-) Well, the "correct" answer given in the guide is to not use it, but let's explain what it does anyways. The question really should have been to explain the difference between virtual and regular inheritance, although this does venture into obscure trivia territory because I'm not sure I've ever seen someone use it or want to use it in over a decade of C++ programming...
> 9. What does the acronym OOPS stand for?
This is a worse-than-useless interview question. For starters, I've only heard it as OOP (object-oriented programming), so I have to guess at the S. It has nothing really to do with C++ in particular, especially as C++ has been growing in non-OOP ways in the past decade. Finally, the question doesn't ask to explain or contrast OOP with other paradigms, it just asks you to say that you know its abbreviation. You can know an abbreviation without understanding anything else--I know that SU(3) means Special Unity group of degree 3 but I literally know nothing else about it.
> 13. Define an inline function.
> This is when a function is prefixed and the keyword ‘inline’ is placed before the function definition. They often work faster than normal functions as the compiler replaces the definition of inline functions at compile-time instead of the referring function definition at run-time.
... That's not correct. In C and C++, a function can only have one definition in general. An inline function--which can be specified either by adding the inline keyword or by giving the function body within the class definition--circumvents this rule, instead supplanting it with a rule that the linker must discard all but one copy of the function.
Note that compilers do not generally treat inline as a hint as to whether or not to inline a function, they use their own heuristics instead (incidentally, the register keyword falls in the same boat). Obviously, the function cannot be inlined if its body is not present, but equivalently replacing inline with static would generally have the same impact on inlining.
- n4r9 8y agoIt's "special unitary" but I fully agree with the sentiment =]