top of page
  • Writer's picturePradeep P

Popular topics for C++ interviews

I recently attended a few technical interviews for the role of a senior C++ software engineer / design lead and would like to put up here a set of topics that are popular with the interviewers. To give you a context, I have about 9 years experience as a software engineer, with most of it in C and C++. If this matches you, you can probably expect the same types of questions I encountered. If not, well, have a look anyway, it might help you as well!

Also, I have mentioned a list of resources that really helped me out, at the bottom of this page. Do have a look.

List of popular C++ interview questions (from my recent personal experience):

1. Multi threading : Yeah, I know this is not for a beginner but boy, this is popular. Questions range from things like what is data race, what are deadlocks, how do you achieve thread synchronization, to things like designing a thread safe queue or a stack. Mutex, Semaphore, Conditional Variable, Critical Section, etc. are all on the table. C++ provides a nice thread library (in <thread>) since C++ 11. I learnt this well and this has sufficed for now. If you have some time and would like to learn this topic, have a look at the following video series. It helped me a lot:



2. Design patterns : which design patterns do you know? Which have you used? How do you implement a singleton? how do you implement an observer pattern? etc.

3. STL : Mostly questions on containers like vectors, queues, deques and maps. Some basics of unordered containers will help. When to use vectors vs when to use queues and tradeoffs? Some allow you to use these in the programs that you write.

4. Strings and related puzzles : Can be as simple as reversing a string and can go on to things like printing all permutations of a string! I was even asked on how to find anagrams in the dictionary (it basically involves using a hash map / unordered_map and a nice hash function). I will upload the code for this soon on to github.

5. Smart pointers : difference between unique_ptr and shared_ptr, how to implement a shared_ptr like class, advantages of using these over the convetional raw pointers, etc.

6. Virtual / inheritance and corner cases using these topics : (was asked how to prevent inheritance of a class, without using the “final” keyword, apparently it can be done using a combination of hidden constructor and virtual base class, need to try this out). Many small questions are based on these topics and are mostly objective based.

7. Object Oriented programming : Classes, structures and some objective questions on this. Questions on topics like abstraction, encapsulation, etc.

8. Design questions -> Designing some simple systems to complicated ones. Design a class for an elevator, design your own string class, design a bookmyshow like app, etc. Some might ask for some basic architecture and block diagrams, some ask for everything like the threads that will be spawned, what thread does what, how are they communicating between each other, how are they synchronized, etc. This can test you on various levels like OO design, multi threading, scalability, etc. It is particularly important that you collect the requirements before you start answering the questions here. For e.g., a particularly popular question on OO design is to design a parking lot, apparently. Though I have not personally encountered this question from a OO design perspective, I have seen it appear in multiple places. Ask all the relevant questions like “Are all parking spots of same size?”, “Once initialized, should the number of parking spots be constant?”, “Are there multiple levels in the parking area and should we consider this?”, “What happens when a new car arrives and there is no parking space left?”, etc. Even though you know what happens in these scenarios in real life, still ask them out. No harm in doing so. If you don’t put a trivial thing as a question, at least state that as an assumption. You can say “I will throw an exception if you try to bring a new car to the already full parking lot, I hope that is fine”.

7. The dreaded Algorithms and Data structures : I shall be frank, I am still studying these topics. I have had questions asked on basic arrays that I couldn’t answer! Be prepared for the worst here! Some companies are known to focus more on this than on the C++ language itself. Check beforehand on sample interview questions about the company’s interview patterns on GlassDoor, GeeksForGeeks, etc. Stacks, Queues, string algorithms, dynamic programming (find the longest matching subsequence), back tracking, recursion and trees are the common topics for questions. You might not be asked to write a program on most of these topics like trees, etc. since it will take some time. You might be asked for the logic for the same, though. I was asked to print the nodes of a binary tree, diagonally (assign each diagonal a number and put the next diagonal’s number as 1 + current diagonal number and then use a hash table to capture the nodes, try this out :). I couldn’t get this, the interviewer told me on how to do it. ) There is basically no limit on what can be asked here. I mean, I couldn’t get an array related question answered! So, keep preparing on this.

8. Debugging and Trouble shooting : GDB, WinDbg and Visual Studio Debugger are asked about, especially if you put them on your Resume. One really tough interview had the interviewer asking me about how to debug a crash happening on a customer PC, if no debug logs are enabled (since they are usually disabled in production releases). Also, how do you configure your program to generate a core dump and use the same with GDB? How do you determine where the program crashed from, in a multi threaded program? What are the steps to configure your Visual Studio to enable and be able to analyze core dumps? These questions are not very common but might come in some times.

9. Compiler and OS related topics : Again not very common or popular from my recent experience. One interviewer dug into how the compiler treats inline functions, how malloc and free are implemented, etc. Among OS concepts, I have not encountered much on memory / scheduling / paging, etc. In one of the online tests, I had a few questions on these topics but other than that, not a common occurrence.

A few basic tips I have learnt:

1. Ask all your questions about their question, before starting to code or even answer. Thus, collect the data before starting your answer. Make sure you have checked and obtained all the information required before starting. This is very very important. This exhibits your skill for requirement gathering. For e.g., if they ask you to implement an elevator class, you can ask questions like, will the number of elevators be changeable at run time, will the controller be part of the elevator or will it be an external class, etc. Don’t leave anything to assumptions.

2. If you are making some assumptions, check with the interviewer first. Thus, you can say something like “I will not be considering multi threading in this program” or “I am not considering corner cases here”. Check if this is OK

3. If you don’t know the answer, be frank. Tell them that you are not aware but if you have some idea on how it can be done, you can probably run it across them.

I shall update this page if I can think of more things (or if I come across more new questions) 🙂 Hope this helps.

Some relatively though questions I faced and some related topics:

  1. Size of an empty class -> Answer: This is going to return 1 since the having a size of 0 means two consecutive objects shall occupy the same memory address. To prevent this, compiler assigns a size of 1 byte to an empty class.

  2. Explain the detailed behavior of the compiler

  3. How does free know the size of the memory to recover

  4. How does malloc know which block of memory is free

  5. How to enable core dumps in Visual Studio and Unix?

  6. How to customize the core dump names that get created? (like adding application name, etc.)

  7. A program can crash multiple times. By default, the core file overwrites any previous one. How to avoid this?

  8. Is there a way to break the compiler behavior?

  9. Is there a way to capture the stack frame of a called function, before it gets popped off?

  10. How can we get the altered value of a variable, passed by value, from the called function, in the calling function? (the hint I got from the interviewer for this was to try and alter the compiler behavior but I have no idea how!)

  11. How to debug a crash using Visual Studio, assuming that the customer doesn’t know the exact steps to reproduce the issue?

  12. How to debug a crash if we didn’t get any crash logs and the issue is not consistent?

  13. How to debug a crash with VS if we got the core dump? (what all supplementary files are needed for the same)?

  14. How to debug a crash with GDB, in the above scenarios?

  15. What all information can a core dump file provide?

  16. How to debug if a software is hanging?

  17. How to debug a multi threaded application on Windows and Unix?

I will update the answers to these questions once I find them out. 🙂 Of course, I will add more questions if I encounter any.

Some very useful resources that I would recommend:

1. http://www.bogotobogo.com/cplusplus/cpptut.php (I am in love with this page, has quite a lot of information. Not an end to end resource to learn C++ but you can search for any specific topic you want to learn here and if you find it, go through it. It is very well put)

2. http://www.learncpp.com/ (Superb webpage, has very well categorized and detailed info on the modern C++)

3. Professional C++ (My go to book for C++. Has covered quite a lot of intricate topics upto C++ 14. Don’t start with this, as the author himself says that this is not for beginners. There is a friendly crash course in the first chapter, try that out and then decide if you want to proceed with this right away or take it up later)

4. Sams Teach Yourself C++ in One Hour a Day (A very good beginner’s book for C++ 11 and beyond)

5. The C++ Standard Library: A Tutorial and Reference (an extremely detailed book on STL. Don’t start with this, you will get depressed since it feels like each new line has a new concept)

6. Data Structures and Algorithms Made Easy (superb book for learning DS and Algos. Examples and solutions are in C but you can adapt on it)

7. geeksforgeeks.org (for info on general programming, DS and algos)

8. http://www.oodesign.com/ (For design patterns)

10. http://www.andiamogo.com/S-OOD.pdf (Some 10 OO Design related questions, like designing a parking lot, etc.)

11. ALGORITHMS (by Sanjoy Dasgupta, Christos Papadimitriou and Umesh Vazirani) Have not read much of this book but one main thing is that it is not scarily fat! I think this is the official link for the PDF version of an older edition: (click here)

Good luck!

94 views

Recent Posts

See All

Comments


bottom of page