C++ Interview Questions

Started by
24 comments, last by Washu 12 years, 6 months ago
" the one you know the answer to but the interviewer has wrong"

Frankly, it's amazing how common that is. One of the problems with these things is that all too often they degenerate into an opportunity for interviewers to make themselves feel better. And quite often they're over-reaching their own technical skills.

Fizzbuzz or reverse a string is entirely sufficient to lose the maybe 60% of candidates who actually can't program AT ALL[1]. Anything beyond that is frankly labouring the point; esoteric questions about the C++ spec are boring for everyone concerned and have no relation to work actually done. (It was amazing the amount of interviews I went to as an IT contractor which were all about weird tricky edge cases of C++ exception throwing, but when I actually started work there, the codebase doesn't use exceptions because the developers aren't confident enough at using them. And usually therefore they're banned...)




[1] What I find slightly bonkers is that a substantial number of these candidates actually think they are good developers and are surprised to find themselves struggling. It seems to stem from being in large matrix-managed teams where one can spend many many years being only borderline competent at developing without anyone noticing. The actual output of the team is caused by the work units being regularly and randomly swapped between members until (eventually) they're done by the one or two competent developers. In many industries this is normal working practice[2], and staff can truly believe they're contributing because the work units passed through their hands. Likewise I meet an amazing number of highly experienced OO devs who, on closer inspection, have actually spent many years going to meetings where some OO design got done... not *necessarily* by them.

[2] And the appallingly low productivity is (in a storming bit of double-think) considered normal because... well... software developers just actually aren't very good are they? Well, on average NO, they're not...
Advertisement

" the one you know the answer to but the interviewer has wrong"


That's why I figured making it the point to be wrong. In short, it's a horrible piece of code essentially just appending one c-string to another.. except using all the awful things I've encountered in peoples code, from tacking every problem by typing "while(1) switch(x)" on autopilot, to the annoying "while(1) break, break, break" pseudo-goto, off-by-one bugs, non-descript names. The point is essentially to just ask "what is wrong with this code" and let him bash away (always hoping for "how about using std::string and += instead of this twisted mess?")

The only time I had an interested test to do was essentially "offline" (ie. they send you the questions and expect you to write back in finite time). Stuff like:

-The AI needs to navigate through x waypoints, implement the move function
-Optimize this code (if in nested loops to check if youre in the second half)
-Silly things (finish this linked list implementation, add 1 to unsigned int with only shifts and logical ops)
-Refactor this code

And my favorite, which I kept for not being one of those silly bit-fiddling questions (in summary):

Imagine a chess board as 8x8 columns of different height. Now imagine pouring water over it (which will of course drain off at the edge of the board). Describe an algorithm to calculate the amount of water the board can hold.

Implementation was not wanted, only a description of the steps. Of course after sending back the test I couldn't resist to create a simple OGL program to generate random boards, calculate the water level at each sell and render it for "visual verification".
f@dzhttp://festini.device-zero.de
In a coding test I had to do sorting, binary search, and a quick pathfinding problem. I've had to read from a file and put it back in sorted order. I've had to create two signals and have them trigger one another (based on some criteria).

In interviews I get the 'reverse a null terminated string', 'now do it in place', 'now do it in place with no temporary' path pretty much all the time.
I can't get into the details of real interviews I've had, because of NDAs and such, but here's a few generic things to be comfortable with:

  • Basic algorithms: search, sort, and various applications of recursion
  • Basic data structures: arrays, lists, trees, heaps, hash tables, etc.
  • Tree/graph traversal methods - know the difference between depth-first and breadth-first and why each one is preferable in certain circumstances
  • Pre-order, post-order, and in-order traversal is a good one to know as well
  • Simple string processing at the byte/character level
  • Elementary bit manipulations - at the very least, know how bitmasking and such work
  • Simple analysis of existing code to find missing functionality
  • Implementation of new functionality in a fixed, unchangeable code base


Last but very much not least, know how to describe your thought processes in detail and with precision. If you're given an hour to do a two hour job, do your best in 45 minutes. Spend the remaining 15 minutes documenting/explaining exactly where you could improve and why you chose the trade-offs you did. This is a common curve-ball to throw at people in my experience, so be ready for it.

Overall... if you can pick up someone else's code, modify it, and produce something that works, you'll probably be OK.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks guys. Theres a good bit of material here!

Sometimes I'm puzzled by how much is expected out of a programmer. I'm about to graduate from the University of Texas at Austin.... a top 10 CS university where they don't teach you C++ until you're final semester in an OS class, and by teach you C++ I mean have you write a few basic functions in C. Yet straight out of college we are expected to be professional C++ programmers. Luckily I have worked with C++ quite a bit in my free time, but I haven't had the opportunity to program in nothing but C++ for a few years to really master the language.

Outside of the language we have these data structures, bit manipulations, and random algorithms that you learn once and only use on a blue moon (at least in college) and then are expected to know off the top of your head. I don't know how anyone could do it without having years of professional experience or spending a few weeks before interviews memorizing every potential question.

Majoring in CS is generally much more demanding then most majors and then we are expected to go above and beyond that in our free time. I guess were not allowed to get exercise or have lives =)

I guess that's why some people get paid the big bucks. I'll just have to prepare as much as I can and hope for the best.
You should've perhaps specified what sort of position you were looking for example questions for (or perhaps we should've).

I suspect a lot of the people here didn't get these questions when they interviewed as entry level devs. And the tone of interviews varies a lot depending on your industry and even location. Up here in Minnesota, you're lucky to get any technical questions at all. Out in silicon valley, even the most laid back company still has a fairly rigorous technical gauntlet.
Apoch has had the best answer so far. The point, after all, is not to memorize clever answers to a few popular problems, but to have a solid grasp of the wide range of fundamentals that these TYPES of questions are meant to evoke. Besides, a good interviewer will recognize a recalled answer, rather than one which is truly being thought out, even if you fake the discovery aspect. Honestly, if you get a question you already know, that should be the first thing you reveal to your interviewer. They may ask you to do it anyways, in which case you want to show that you understand the solution you have (and also that you are sure there are no holes in it.)

In addition to algorithm-ish stuff, also know basic oop and language stuff -- what are the 3 pillars of oop? What are the 3 kinds of inheritance and under what situations are they useful (properly used, not how they work)? What is a 'volatile' variable, and what's an example of when you might use it? Describe how 'public', 'protected', and 'private' affect member visibility. Know what 'static' means in all the various contexts it can be uses. Those types of things.

throw table_exception("(? ???)? ? ???");


You should've perhaps specified what sort of position you were looking for example questions for (or perhaps we should've).

I suspect a lot of the people here didn't get these questions when they interviewed as entry level devs. And the tone of interviews varies a lot depending on your industry and even location. Up here in Minnesota, you're lucky to get any technical questions at all. Out in silicon valley, even the most laid back company still has a fairly rigorous technical gauntlet.


Haha, good point. I'm hoping to get into the gaming industry as that is what I spend most of my free time working on and have the most experience with (and of course what I am passionate about). This of course means strong C++ skills required. In my free time I made a WebGL/JavaScript engine which has a lot of basic 3D game engine functionality www.cs.utexas.edu/~josh4689 (feel free to criticize). I feel that I have a pretty solid foundation about how the basic mechanics in a game engine work. Plenty of experience with vector/matrix math, basic lighting techniques, basic skin-and-bone animation, simple terrain (with GeoMipMapLoD), bounding volumes, quite a few intersection algorithms, picking, most of the basic geometry used, view frustum culling, and parsing Collada files.

Unfortunately most of the big companies don't seem to be interested in hiring an entry level software engineer. Bungie has a few openings I feel I am qualified for. Keeping my fingers crossed.
You should have been born in Japan. Here, they almost only hire out-of-college kids. Before you even graduate you already know at which company you will be working, and you will work there for basically your life.

That being said raises a point. You don’t have to seek only within America. I started my career in video games overseas. Keep in mind that the world is your oyster, not just your country.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Heh. While I am a big anime fan, I'm also 6'2. I would stick out like a sore thumb! On a side note, could one only speak english and still work over there?

This topic is closed to new replies.

Advertisement