Language basics
1. Pointer vs reference?
A pointer stores an address, can be null and can be reassigned; a reference is an alias that must be initialised and cannot be reseated.
2. What does const do?
It marks a value, parameter or member function as not modifying data, which documents intent and lets the compiler catch mistakes.
3. Pass by value vs pass by reference?
By value copies the argument; by reference passes the original, avoiding copies and allowing changes. Use const references for large read-only arguments.
4. What is function overloading?
Several functions with the same name but different parameter lists; the compiler chooses one based on the arguments.
Object-oriented programming
5. What are the four pillars of OOP?
Encapsulation, abstraction, inheritance and polymorphism.
6. What is a virtual function?
A member function that can be overridden in a derived class and is chosen at runtime through a base-class pointer or reference.
7. Why should a base class have a virtual destructor?
So deleting a derived object through a base pointer calls the derived destructor and frees everything correctly.
8. What is an abstract class?
A class with at least one pure virtual function; it cannot be instantiated and defines an interface for derived classes.
Memory management
9. Stack vs heap?
The stack holds local variables with automatic lifetime; the heap holds dynamically allocated memory that lives until it is freed.
10. What is a memory leak?
Allocated memory that is never freed. Smart pointers and RAII prevent most leaks.
11. unique_ptr vs shared_ptr?
unique_ptr has a single owner and cannot be copied; shared_ptr allows shared ownership with reference counting.
12. What is RAII?
Resource Acquisition Is Initialisation: tie a resource to an object’s lifetime so it is released automatically in the destructor.
STL
13. vector vs list?
vector stores elements contiguously with fast random access; list is a linked list with fast insertion in the middle but no random access.
14. map vs unordered_map?
map is ordered (usually a balanced tree, O(log n)); unordered_map uses hashing with average O(1) lookups and no ordering.
Data structures
15. How does a binary search tree work?
Each node’s left subtree holds smaller values and the right subtree larger ones, giving O(log n) search when balanced and O(n) in the worst case.
16. What is Big-O notation?
A way to describe how running time or memory grows with input size, for example O(n) for a single loop.
17. How would you reverse a linked list?
Walk the list with three pointers (previous, current, next), reversing each link, in O(n) time and O(1) extra space.
Practise with real projects in the free C++ internship, or read the C++ career guide.
Common questions
What C++ topics are asked most in fresher interviews?
Pointers and references, OOP and virtual functions, memory management with smart pointers, STL containers and basic data structures and complexity.
How should I prepare for a C++ coding round?
Solve problems on arrays, strings, hashing and trees in C++, and explain your approach and complexity as you code.
