I've got about 2/3 years C++ experience but I've spent most of my career doing Java. I'm about to go for an interview for a C++ programming role and I've been thinking about the best way to brush up my C++ to make sure I don't get caught out by any awkward questions. What would you recommend?
views:
447answers:
10If you have enough time try to write an application using C++ - go over the basics so when you'll be asked to show coding skills you'll be able to write code fluently.
I've noticed that during C++ centric interviews it is common practice to ask question about how it works:
- How virtual methods are implemented?
- What happens when you call
new
- how memory is allocated? - What is the difference between struct and class?
- Why should you mark your class d'tor as virtual?
I guess a good way to learn all those is to read a good C++ book - if you have the stomach for it you can read Stroustrup book - but there bound to be other books just as good (with less pages in them).
Have a look at the C++ Style and Technique FAQ
It depends: I went for a job with a certain large games company and 90% of the questions were graphics and micro-optimisation questions (this was for a C# testing role, stupidest test of my life!).
However, if you're going for a normal desktop-app role, you'll probably get asked about UIs, or if you're going for some sort of embedded computing role you'll likely be asked about optimisation and memory management.
In any case, I'd brush up on your BOOST, as an example of a good library, and your pointer knowledge.
As an interviewee, I depend on experience. As an interviewer, my favourite (and often only) C++ interview question is "Tell me about the copy constructor". It's amazing how many avenues this opens up, and how few people are aware of them - it can make for a very short interview. If the interviewee gets past that, I then ask "Which are your favourite C++ books, and why?"
Know the language. You can try to predict what questions they'll ask, but C++ can mean a lot of different things depending on who you ask. To some people, it's a clumsier Java, and all the questions will be about dynamic memory allocation, virtual functions and inheritance. To others, it's all about RAII, and avoiding memory management.
Some think the STL is the most important to ask questions about and some might want to dig in to your knowledge of some of the subtler aspects of the language (ranging from the copy constructor that Neil mentioned in his answer, to common cases of undefined behavior, or exception safety)
It's a big, complex language, and people can ask a lot of different questions about it. Unless you have some idea what areas they're likely to focus on, you're not likely to achieve much with last-minute brushing up.
I would just review the basics of the language: make sure you remember how to make classes, know when to pass it via reference and when to pass in via pointer, and why you'd want to do that vs pass by value. Why you'd want a virtual method, and what are the reasons one uses the C++ style casts vs the C style casts, when you'll need a copy constructor, things like that
I'd imagine what would help is remembering a war story or two about C++: ("man, const correctness is hard!", "so I once got into a fight with a coworker/teacher about this finer point of C++, and I learned that.."
If the job is for an entry level C++ job (which it should be with your limited C++ experience), I'd imagine that would be fine and that you'll (hopefully) not get cast too deep without a paddle/senior engineer to guide you.
"write a function that counts the number of 'on' bits in a byte"
that never gets old...
I saw a cool bitwise way of doing it once that could count all the on bits in a 32 bit DWORD in like 4 or 5 operations!
If I were an interviewer in this day and age I'd ask "what do you know about lock free codeing?"
Must have C++ books for every advanced programmer:
Herb Sutter Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions
Herb Sutter More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
Herb Sutter Exceptional C++ Style: 40 New Engineering Puzzles, Programming Problems, and Solutions
A.Alexandrescu and Herb Sutter C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
Scott Meyers Effective C++: 55 Specific Ways to Improve Your Programs and Designs
Scott Meyers More Effective C++: 35 New Ways to Improve Your Programs and Designs
- Scott Meyers Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library