On this page
- Input and output
- Headers and namespaces
- Structs and classes
- Object-oriented programming in C++
- The standard library
- Common string work
How to prepare
Frequently asked questions
Related reading
C++ Interview Questions: Core Concepts, OOP, and the STL


On This Page
- Input and output
- Headers and namespaces
- Structs and classes
- Object-oriented programming in C++
- The standard library
- Common string work
How to prepare
Frequently asked questions
Related reading
C++ interview questions fall into a small number of groups. Interviewers ask about input and output, about how the compiler finds your code, about how classes behave, and about what the standard library gives you. The same handful of concepts appear again and again.
This guide walks through those groups. Each section links to a detailed answer if you want to go deeper on one topic.
1. Input and output
Almost every C++ program starts with a line that prints something, so interviewers often open here to check that you understand what those symbols actually are.
cout and cin are objects, not keywords. cout is an output stream object defined in the <iostream> header, and cin is the matching input stream object. Both live in the std namespace.
The << symbol is the stream insertion operator. It is the bitwise left shift operator that the standard library has overloaded to mean "write this value to this stream". This is worth saying out loud in an interview, because it shows you understand operator overloading rather than treating << as special syntax.
endl writes a newline and then flushes the stream. That flush is the part candidates miss. If you only need a line break, '\n' does the same thing without forcing the flush, which matters inside a loop that prints a lot of output.
The += operator is a compound assignment. It adds and assigns in one step, and like most operators it can be overloaded for your own types.
2. Headers and namespaces
#include is a preprocessor directive. Before the compiler runs, the preprocessor replaces the #include line with the entire contents of the named file. It is a textual copy, which is why include guards exist: without them, including the same header twice would define everything twice.
A namespace is a named scope that groups related names. It exists to prevent collisions. Two libraries can both define a function called sort as long as each one sits in its own namespace. The standard library uses std, which is why you write std::cout unless you have brought the name into scope.
3. Structs and classes
In C, typedef struct is a common pattern because C requires the struct keyword at every use. The typedef creates an alias so you can write the type name on its own. C++ does not need this, since the struct name is already usable as a type.
That leads to a question interviewers like: when should you use a class instead of a struct? In C++ the only language-level difference is the default access level. Members of a struct are public by default, members of a class are private by default. Everything else is identical. The real difference is convention: most codebases use structs for plain data and classes for types with behavior and invariants to protect.
Access levels come up directly too. The difference between private and protected is about derived classes. Private members are not accessible to a derived class. Protected members are. Both are inaccessible from outside the class.
The friend keyword grants a function or another class access to private and protected members. It is a deliberate hole in encapsulation, so the honest interview answer is that you use it rarely, most often for operator overloads that cannot be members.
A getter is a member function that returns the value of a private field. It exists so that the class controls how its data is read, which is the point of keeping the field private in the first place.
4. Object-oriented programming in C++
This is the largest group of questions. OOP in C++ rests on four ideas, and interviewers usually ask you to define each one.
Encapsulation is bundling data with the functions that operate on that data, and restricting direct access to the data. Data abstraction is exposing only what a caller needs and hiding how it works. The two are related but not identical: encapsulation is the mechanism, abstraction is the result.
Inheritance lets one class take on the members of another, so shared behavior is written once. Polymorphism lets a call through a base class pointer run the derived class version of a function.
Polymorphism is where the follow-up questions live.
Virtual functions are what make that work. Marking a member function virtual tells the compiler to resolve the call at run time based on the actual object type, rather than at compile time based on the pointer type. Overriding is the act of a derived class providing its own version of that virtual function.
That distinction is exactly what binding means. Static binding is resolved at compile time. Dynamic binding is resolved at run time, and virtual functions are how C++ opts into it.
A destructor runs when an object goes out of scope or is deleted, and it releases whatever the object owns. The interview follow-up is almost always the same: if a class is meant to be inherited from and deleted through a base class pointer, its destructor must be virtual. Otherwise only the base part is destroyed and the derived part leaks.
5. The standard library
The STL questions are narrower but they separate candidates who have used C++ from candidates who have only read about it.
string::npos is a static constant equal to the largest value the string size type can hold. Functions like find return it to mean "not found". You compare against std::string::npos rather than checking for -1, because the type is unsigned.
std::map is implemented as a red-black tree, which is a self-balancing binary search tree. The standard does not name the data structure, but it requires ordered iteration and logarithmic lookup, insertion, and deletion, and a red-black tree meets those guarantees. This is a good question to reason through out loud rather than recall.
A related question is why the STL has no general tree container. The standard library specifies containers by their interface and complexity guarantees, not by their internals. A bare tree has no single obvious interface that would suit every use, while map and set already expose the ordered behavior most code needs.
6. Common string work
String manipulation shows up in the coding round itself. Reversing a string in C and C# covers both languages, since the question is often asked without specifying which one.
If you want to know which topic in C++ is hardest, the common answer is memory management and pointers, followed by templates. Both reward practice more than reading.
How to prepare
Knowing the definitions is the floor, not the goal. C++ interviews still spend most of their time on problem solving, and the language questions are checks along the way.
If the algorithmic side is the weaker half, Grokking the Coding Interview teaches the recurring problem patterns rather than a list of individual problems, which is what transfers to a question you have not seen. If data structures themselves are shaky, Grokking Data Structures covers them before the patterns rely on them.
Frequently asked questions
Is C++ a good language for coding interviews?
Yes. It is fast, it is accepted at every major company, and its standard library covers the containers most problems need. The tradeoff is that it is more verbose than Python, so you write more code under time pressure.
Do interviewers ask about pointers and memory?
For C++ roles, often. Expect questions about ownership, when memory is released, and why a base class destructor should be virtual.
How much of the STL do I need to know?
Vector, string, map, unordered_map, set, and the common algorithms such as sort and find. Knowing the complexity of each operation matters more than knowing every method name.
What is the difference between overloading and overriding?
Overloading is several functions with the same name and different parameters, resolved at compile time. Overriding is a derived class replacing a virtual function from its base, resolved at run time.
Related reading
What our users say
Simon Barker
This is what I love about http://designgurus.io’s Grokking the coding interview course. They teach patterns rather than solutions.
KAUSHIK JONNADULA
Thanks for a great resource! You guys are a lifesaver. I struggled a lot in design interviews, and Grokking System Design gave me an organized process to handle a design problem. Please keep adding more questions.
MO JAFRI
The courses which have "grokking" before them, are exceptionally well put together! These courses magically condense 3 years of CS in short bite-size courses and lectures (I have tried Grokking System Design Interview, OODI, and Coding patterns). The Grokking courses are godsent, to be honest.
Access to 50+ courses
New content added monthly
Certificate of completion
$31.08
/month
Billed Annually
Recommended Course

Grokking the Coding Interview: Patterns for Coding Questions
191,028+ students
4.6
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
View CourseRead More
Mock Interview Practice for Engineers: 3 Formats + a Readiness Checklist
Arslan Ahmad
Complete Coding Interview Preparation Roadmap for 2025
Arslan Ahmad
Thread Safety 101: Designing Code for Concurrency
Arslan Ahmad
Mastering the Meta Technical Screen: A Comprehensive Guide for Senior Software Engineers
Arslan Ahmad