C++ interview preparation [closed] - c++

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I have a Phone interview coming up next with with a company which works in financial software industry. The interview is mainly going to be in C++ and problem solving and logic. Please tell me the method of preparation for this interview. I have started skimming through Thinking in C++ and brushing up the concepts. Is there any other way I can prepare?? Please help.
Edit:
Thank you all everyone for the advice. I just want to add that I am currently fresh out of grad school and have no previous experience. So Can you suggest some type of questions that will be asked to new grads??

Make sure you know your basic data structures and algorithms. You're more likely to be asked about that stuff than something higher up the food chain. Those are usually saved for the in-person interview.
Put another way: be solid with the fundamentals and solid with your C++ syntax. Also, knowledge of common libraries like STL and Boost couldn't hurt...but be sure you know what those libraries give you! In the end phone screens are there to cull out people who can't do the basics. Prove you can and you should move on to the next step. Good luck!
Here's some links of interview questions to check out:
C++ Interview Questions # DevBistro
C++ Interview Questions # Blogspot
C++ Interview Questions # FYI Center
Steve Yegge's Five Essential Phone Screen Questions (added this in response to your edit. This isn't C++-only, but a lot of it applies to C++ and I think would be a good read in your situation).
Now, for completion's sake, some books:
Scott Meyers "Effective" series (Effective C++, More Effective C++, Effective STL)
Herb Sutter's "Exceptional" series (Exceptional C++, More Exceptional C++, Exceptional C++ Style)
The C++ Standard Library by Josuttis
C++ Primer by Lippman et al
Stroustrup's text as a reference

I have interviewed several candidates specifically focusing on their C++ knowledge, and if there was one question that worked well to put peoples' knowledge of C++ on a gradient, it was this one:
Fix this memory leak as robustly as you can:
void doSomething()
{
Foo* pFoo = new Foo();
[do some stuff]
}
+1 for putting delete pFoo at the end
+2 for putting pFoo in a std::auto_ptr
+3 for knowing what RAII is - the concept, if not the acronym
+4 for mentioning exception-safety guarantees of the auto_ptr
+5 for putting pFoo in a boost:shared_ptr
+6 for knowing when a shared_ptr might not be freed.
+7 for talking about garbage collection techniques to fix circular references
This always worked to show how long someone had been working with C++. This is one datapoint you can use to tell where you are in the scale of C++ knowledge.
Edit: I would recommend someone for hire at level 3 or above.

Try some practice problems on TopCoder.
Check out Marshall Cline's C++ FAQ. Its a good way to learn some new stuff and bone up on the things you already know in case the decide to ask you some 'knowledge' questions as opposed to 'problem solving' questions.

Grab a knowledgeable friend and have them ask you some C++ programming problems that you can solve on a whiteboard. A lot of interviews will have you solve a problem on a whiteboard, and it can be disconcerting to think on your feet and write things out in front of someone if you are not used to it.

Even if they're interviewing for a C++ position not all questions may be specific to C++. For example, I've been hit with questions related to the following all in the same set of interviews for a single C++ position:
Algorithmic complexity of well known sort and search algorithms
Multithreaded programming
Multiprocess programming
Sockets programming
Software development philosophy / approach
Software test and validation philosophy / approach
Debugging
Benchmarking
Dynamic and static analysis of code (e.g. run-time memory leak detection vs compile-time)
In my case, the phone interview was part of a screening process to determine if I could take an online C/C++ knowledge test (e.g. through BrainBench). The online test results then determined if I would be flown out for on-site interviews, which also included more "hands-on" software development tests.
YMMV. A lot depends on what you claim on your resume, as well.
Interviewers often try to help you by giving you hints so that they can see if you can arrive at the answer they're looking for. Besides gauging your knowledge, they also want to see how you think. Occassionally you might get a crummy interviewer that is neither helpful nor positive. The key is to be confident in your abilities and be truthful.
HTH and good luck!

Something which I am starting to believe is that there is sometimes a clear divide between candidates that enjoy programming as a hobby versus those who consider it "just a day job".
Even if you don't know the answer to a specific question it is worth mentioning that normally you'd look up the answer on < your favourite resource > (eg. StackOverflow).
Based on your experience I don't think the interviewer will expect that you'll get every question right. They're most likely trying to decide if you've got "potential".
So relax and try to enjoy it!

Besides the obvious parts of the language, I've found that employers will want to see if you fully understand pointers, references, how copy-constructors come into everything, probably STL, and of course the basics of classes.

Read (or skim, depending on how much time you have to prepare) "Large-Scale C++ Software Design" by John Lakos. Chances are, you will need it.

Related

What technique would you recommend when reviewing C++ for an interview? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
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?
Effective C++ by Scott Meyers
If 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
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.
Go through the questions on SO with
C++, OOP tags.
C++ FAQ
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
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.
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?"

What C++ tutorial would you recommend for an experienced programmer that has some patchy knowledge about the language? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
In my early days of programming, before I started working professionally, I wrote a fair share of trinket/exercise apps in C++ and felt fairly confident that I know the language. Then, as opportunity came, I went to do real work and left the C/C++ world. For the past 5 years I've written tons of code in C# and have had scarcely any encounters with the C/C++ languages. Now, after spending some time on SO and teh interwebs, I see that what I thought I know as "C++" is actually a mix between C and C++, with large gaps in my knowledge about the more intricate workings of the language. At the same time I also realize that I am intrigued by the language and would like to learn it more.
Googling for "C++ tutorials" reveals a wealth of tutorials, but they are all aimed at complete beginners, spending a lot of time explaining basics that I'm already familiar with. I don't expect that there will be any tutorials made exactly for me, but are there some that have at least been written with an experienced programmer in mind, not spending a lot of time on trivial things, and discussing the finer points of the language and compilers?
C++ is too complex to be learned through tutorials, you could only scratch the surface that way. Especially the advanced usage of the STL (and templates in general) is usually beyond the scope of online tutorials.
Therefore, I would recommend books: Stroustrup's "The C++ Programming Language", and Scott Meyer's "Effective C++", "More effective C++" and "Effective STL".
You can skip the first few chapters of Stroustrup if you feel confident you know that part already, but it's the best book for going into the details of the language. There should be a law for every aspiring C++ programmer to read at least the first two of Meyer's books I mentioned.
Once you're through with that, check out "Modern C++ Design" by Andrei Alexandrescu for a real eye-opener for what templates can be used for.
Update: In reaction to a downvote eight years later (...), be aware of The Definite C++ Books List. My personal recommendations above hold true, but that list is community-driven.
C++ is a very old language so there are lots of good books available. I would recommend to read those books, rather than searching sites and blogs. My personal experience says in harder to find lot of good articles at one place, by most of the good articles are already in books.
Regarding sites:
Dr. Dobb's site and journal have lots of good articles.
Books:
Effective C++
Exceptional C++
C++ Object Model
Bjarne Stroustrup
Beyond the C++ Standard Library
I suggest, though rather as supplement, the C++ FAQ Lite. It has information ranging from basic things to really obscure C++ features and many tips to write good C++ and helped me more than once when some stupid template thing or whatever wouldn't do what I expect.
1.C++ Object model is nice book for professionals.
2.Design and evolution of C++ by bjarne stroustrup give you in-depth insight.
3.Scott Meyers' Effective C++ series is also nice one.
You've gotten a number of good recommendations, but none seems to have included the one that was really written to fit your situation. Accelerated C++ was written for people who already know the basics of programming, and just want to learn how to program in C++.
Workings of the language? What areas exactly do you think are worth improving? I have a slight trouble extracting it from your question.
One book that i always keep on my table and peek into frequently is C++ Primer by Lippman et al, 4th ed., ISBN 0-201-72148-1. This is not a tutorial, this is a reference. Whenever you have a question about the language itself, this is where you can find a short and precise answer.
If you want specifically a tutorial which aims at experienced C programmers, see Bruce Eckel's Thinking in C++. Available as free download on author's site and also printed through Prentice Hall.
At some point you will have learnt a great many things which you CAN do, from then on, you should learn what NOT to do. This is a long and painful part, and i don't have a precise recipy, but accept my sympathies. The deeper you get involved into complex stuff the more likely is it to bite you at some point due to conflicts between language features. I suggest taking a look at Imperfect C++ by Matthew Wilson, C++ Coding Standards by Sutter and Alexandrescu.
You probably want to skip the stuff you already know and move on to harder more fun stuff. I assume you already know a lot about the language and it's syntax, methods, classes, etc.
Where to start? Well, there are very good books and papers on the language. I can recommend many books on the language but you can probably find them using the stackoverflow search.
I can only tell you what you already know. You wont find a book that covers it all. You will have to browse through many books in order to get what you desire. Take a randomly recommended book, browse through it skip the stuff you know and try to fit it all together. Try to make something out of the fresh knowledge by writing some code to understand it better. Do it until you understand it fully.
Here is a brief tutorial for advanced C programmers to refresh your memory on the language.
Essential C++ by Lippman is a small but great book.

Well written C++ examples [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm currently learning C++ and would like to start reading others sourcecode to pick up tips. I was wondering if anyone has examples of well written C++ that I can take a look at (and not pick up bad habits from)
As you've probably discovered, there are many Internet sources for examples of C++ code. StackOverflow, CodeProject, etc. all have examples of source. But of course, they're all over the map in terms of quality and educational value.
I think, in this area, books still trump the Internet. There's no substitute for going to the bookstore, thumbing through a few tomes, and picking one that you find readable. They've been proof-read (unlike may Internet submissions), so the samples are more likely to work and to be of high-quality.
While the books typically have small snippets of code or a few functions, they usually come with a CD or URL that points you to more full-blown examples.
O'Reilly, Thinking in C++, Petzold, and Wrox (and more) all have good books on C++.
The Boost library? It is generally considered some of the highest quality C++ code written. (A lot of it is also more or less unreadable unless you're a C++ guru yourself, though)
In general, I'd advise against you to be cautious with this approach though. In C++, the source code probably won't be as informative as in many other languages.
If you see some Python code, you can pretty much assume it's correct as long as it runs. If it's written by someone who seems to know what they're doing, you can even assume that it's well written.
In C++, there are just so many nasty pitfalls and subtle exceptions to every rule that you really need to know what you're doing. Going by what compiles, or what seems to work, or what you saw in someone else's source code is dangerous, and pretty much guarantees that you'll sooner or later end up with a program that relies on undefined behavior, and will crash when you least expect it.
If I were you, I'd try to stick to books. There are some very well written ones, which in addition to letting you see some source code, also teach you the langage "properly". And as long as you stick to reputable authors, you're ensured that they won't teach you any bad habits or plunge you into nonportable code.
In my opinion if you read a good C++ book (like "The C++ Programming Language", "(More) Effective C++" or "Exceptional C++").
You will not only learn good practices but should also get sense of how to write code.
Of course the samples in these Books are mostly artifical. If you read 'real-world-applications' you will always encounter pieces of code which are pretty ugly, but sometimes there wasn't just a nice clean solution for it (or a not-so-clean solution was just more efficient in terms of speed).
So I don't know if it's best to start with real applications since they can also be very overwhelming due to the amount of codesize and complexity, whereas sample codes in Books are compact and clearly laid-out.
I think for starters you would be best off reading such references as the books I have listed.
If you have to be flexible at some point in the future and have to produce ugly code, you will at least know that it's ugly code and not mistake it for "that's how it should be" ;)
Reading through open source software can be very educational if you already have a little bit of knowledge of C++. If you're just starting out, I imagine the Boost libraries will go right over your head. You could start with the WebKit project, which is an excellent resource. Also Google releases a lot of their source code, which also happens to be VERY clean: Protocol Buffers is a great example. And while you're at it, you may as well read their C++ Style Guide as well.
Personally, I started learning C++ by picking up a couple of books and writing some little challenge applications. Bear in mind that learning a language as extensive as C++ takes a long time, like 10 years long.
Many years ago, I was told that if I ever wanted a career as a C++ developer, I should definitely read Effective C++ by Scott Meyers. That should prevent you from falling into many of the language's pitfalls. If you find you need something even simpler, start with The C Programming Language by Kernighan & Ritchie. Be patient and good luck!
If you want a complete project to browse through, I would recommend Ogre3d. It is a well structured graphics engine with decent documentation and the source code itself is nice, too.
How about: Programming: Principles and Practice Using C++ by Bjarne Stroustrup?

Is C++ a "waste of time"? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I ran into this supposed interview of Bjarne Stroustrup, the inventor of C++.
http://artlung.com/smorgasborg/Invention_of_Cplusplus.shtml
Stroustrup: Well, it's been long enough, now, and I believe most people have figured out for themselves that C++ is a waste of time but, I must say, it's taken them a lot longer than I thought it would...
Interviewer: Yes, but C++ is basically a sound language.
Stroustrup: You really believe that, don't you? Have you ever sat down and worked on a C++ project? Here's what happens: First, I've put in enough pitfalls to make sure that only the most trivial projects will work first time. Take operator overloading. At the end of the project, almost every module has it, usually, because guys feel they really should do it, as it was in their training course. The same operator then means something totally different in every module. Try pulling that lot together, when you have a hundred or so modules. And as for data hiding, God, I sometimes can't help laughing when I hear about the problems companies have making their modules talk to each other.
Is this a hoax? Do any of these points seem true for any of the veteran C++ programmers out there?
You just have to check the Stroustrup's website (the FAQ part) to find that it's wrong - a well known hoax as Judah Himango already pointed :
Did you really give an interview to IEEE?
in which you confessed that C++ was
deliberately created as an awful
language for writing unmaintainable
code to increase programmers'
salaries? Of course not. Read the
real IEEE interview.
It's a well-known hoax.
And no, learning C++ isn't a waste of your time, something that's been discussed on StackOverflow many times.
As mentioned, this is a well-known hoax.
But it does provoke some interesting points. These days C++ is a waste of time, except for when you can't afford to waste time. Less opaquely: C++ is a waste of development time, except for when you can't afford to waste execution time.
From the article titled "The Real Stroustrup Interview" in IEEE Computer Magazine Vol. 31 Issue 6 pp.110-114 (June 1998):
For the past few months, a hoax interview between Stroustrup and Computer has been making the rounds in cyberspace. While we regret the incident, it offers us a welcome opportunity to have the father of C++ share his insights on Standard C++ and software development in general. We can also attest to his continued sense of proportion and humor—he suggests that the fictitious interview would have been a much funnier parody had he written it himself.
As others mentioned, this Interview is hoax.
Well, I am one of the persons who hate C++ and normally doesnt use it, but learning it was definitely not a waste of time. At least now I know why I hate C++ and I understand why other persons use this language and think it is good.
If you want to learn this language to know about its concepts, its benefits and its drawbacks, to be able to read code written in it, and in general to be able to "talk about" it, it is never a waste of time. Same for any other programming language. It will increase your expierience. For example, C++ shows one common way of OOP - a way I dont like, but a way many other people use.
But if you want to learn it because "the people say that it is the best" (as I sometimes read), then it is really a waste of time. Same for any other programming language.
Programmers that feel attracted to higher level languages that take care of memory management and other tasks for them, could feel that C++ is a waste of time.
It certainly is if you can achieve the same goal with another language in less time and with less bug fixing and don't mind the downsides as efficiency.
But I don't regret having learned and spent so many hours coding in C/C++ for it's such a beautiful language and allows you to produce things that not many other languages can.
I mean, don't you want to use the language with which operating systems and compilers are written? that's not a waste of time at all from my perspective.
C++ is far from being a waste of your time. You'll understand valuable concepts that will help you understand many other concepts in different programming languages. I.E.: VTABLE.
There is not a single framework which uses all language features of C++. This introduces a huge inconsistency to the language's ecosystem.
QT is one of the few APIs which I would call a framework (or API for a lot of things):
But it defines own string, own array, ...
What's the point of a "standard" library when no one can use it in a portable and compatible way (from the aspect of interaction with other APIs)?
I know, there is boost, but what is boost compared to an API such as QT? Nothing.
Look at Java: The is the standard Java API, and every "foreign" API uses it, it's all perfectly compatible.
C++ (and Java) probably the best language to learn to understand concepts of OOP.
I remember learning it in college benefited me a lot.
Stroustrup is not that stupid to say that! It is definitely a hoax!

Get back to basics. How do I get back into C++? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I haven't used C++ since college. Even though I've wanted to I haven't needed to do any until I started wanting to write plugins for Launchy.
Is there a good book to read to get back into it?
My experience since college is mainly C# and recently ruby. I bought some book for C# developers and it ended up being on how to write C++ with CLI. While a good book it wasn't quite what I was looking for.
My favorites are Effective C++, More Effective C++, and Effective STL by Scott Meyers. Also C++ Coding Standards by Sutter and Alexandrescu.
The best way to get back into C++ is to jump in. You can't learn a real language without spending any serious time in a country where they speak it. I wouldn't try to learn a programming language without spending time coding in it either.
I wouldn't recommend learning C first though. That's a good way to pick up some bad habits in C++.
I haven't tried it myself but have heard from people and sources I trust that "Accelerated C++" by Koenig and Moo is a good book for people who want to pick up C++ quickly. Compared to the more traditional route of learning C first then C++ as a kind of C with classes the K+M approach helps you become productive quickly while avoiding pitfalls and bad habits associated with the legacy of the language.
A good starting place is "Thinking in C++" by Bruce Eckel, I've rarely had anyone complain about the book. Well written and also has a version available online.
Another online book that I pick up whenever I need to get back into C++ is "C++ In Action" by Bartosz Milewski. Its online at his site.
The C++ Programming Language by Bjarne Stroustrup covers C++ in depth. Bjarne is the inventor of C++. It also provides insights into why the language is the way it is. Some people find the book a little terse. I found it to be an enjoyable read. If you have done some C++ before it's a great place to start. It is by no means a beginners book on C++.
My book recommendations:
Essential C++ (Lippman)
C++ Common Knowledge: Essential Intermediate Programming (Dewhurst)
...and I second the Effective C++ suggestion above.
A very handy alternative to buying books in meatspace is to subscribe to a service like Safari Books Online. For a not unreasonable monthly fee you'll get access to all of the above books plus a bajillion others. If you desire fast random access to more than a couple books, it pretty much pays for itself. It's an easy case to make if you want to convince your employer to pay for it.
Beyond that, sit yourself in front of an IDE that has a C++ code completion feature (I use Eclipse/CDT most of the time).