CCareerClutch
← All posts
·6 min read·CareerClutch Team

Top C++ Interview Questions for Freshers in India (2026)

interview-preptechnicalfreshers

C++ sits at the core of campus placement technical rounds at almost every product and service company in India — from TCS and Infosys to gaming studios and embedded-systems firms. The questions aren't random. Interviewers follow a predictable pattern: OOP concepts, memory management, STL basics, and two or three tricky output questions designed to catch out candidates who memorised definitions without understanding them.

This guide covers the questions you'll almost certainly face, with answers that go one level deeper than the textbook.


OOP Fundamentals

1. What are the four pillars of OOP?

Encapsulation — bundling data and the functions that operate on it into a single unit (class), and hiding internal state from the outside.

Abstraction — exposing only what's necessary. A BankAccount class lets you call deposit() without exposing how the balance is stored.

Inheritance — a derived class acquires the properties of a base class. Reduces duplication.

Polymorphism — the same interface behaves differently depending on the object. A Shape pointer can point to a Circle or a Rectangle, and draw() does the right thing for each.

2. What is the difference between overloading and overriding?

| | Overloading | Overriding | |---|---|---| | Where | Same class | Derived class + base class | | Signature | Different parameters | Same signature | | Resolved at | Compile time | Runtime (via vtable) |

// Overloading
void print(int x);
void print(double x);

// Overriding
class Base { virtual void speak() { cout << "Base"; } };
class Derived : public Base { void speak() override { cout << "Derived"; } };

3. What is a virtual function? Why do we need it?

A virtual function enables runtime polymorphism. Without virtual, calling a method through a base class pointer always calls the base class version, even if the object is actually a derived type.

Base* b = new Derived();
b->speak(); // "Base" without virtual; "Derived" with virtual

Always declare the destructor of a base class virtual. Without it, deleting a derived object through a base pointer causes undefined behaviour — the derived class destructor never runs.

4. What is a pure virtual function and an abstract class?

A pure virtual function (= 0) has no implementation in the base class. Any class containing one becomes abstract — it cannot be instantiated. Derived classes must override it or they also become abstract.

class Shape {
public:
    virtual double area() = 0; // pure virtual
};

Memory Management

5. What is the difference between stack and heap memory?

Stack: automatically managed, fast, limited size (~1–8 MB). Local variables live here and are freed when the function returns.

Heap: manually managed (new/delete), slower, much larger. Objects created with new persist until explicitly deleted.

6. What is a memory leak? How do you prevent it?

A memory leak occurs when you allocate memory on the heap but never release it, causing the program to consume more and more RAM.

Prevention: always delete what you new, or — better — use smart pointers (std::unique_ptr, std::shared_ptr) which handle deallocation automatically.

// Leak
int* p = new int(10);
// ... forgot delete p

// Safe
std::unique_ptr<int> p = std::make_unique<int>(10); // auto-deleted

7. What is the difference between delete and delete[]?

delete frees a single object. delete[] frees an array. Using delete on an array allocated with new[] is undefined behaviour.

int* arr = new int[10];
delete[] arr; // correct

Pointers and References

8. What is the difference between a pointer and a reference?

| | Pointer | Reference | |---|---|---| | Nullable | Yes (nullptr) | No — must bind to a valid object | | Reassignable | Yes | No | | Syntax | *ptr, ptr-> | Same as the original variable |

Prefer references when you don't need null or reassignment; they're cleaner and safer.

9. What does const int* p vs int* const p mean?

  • const int* p — pointer to a constant integer. You can change p (point it elsewhere) but not *p.
  • int* const p — constant pointer to an integer. p cannot be changed, but *p can.
  • const int* const p — both are constant.

This distinction comes up in almost every C++ interview. Write it out on paper twice before your interview.


STL and Templates

10. Name five commonly used STL containers and when to use each.

| Container | Use when | |---|---| | vector | Need a dynamic array with fast random access | | list | Frequent insert/delete in the middle | | map | Key-value pairs with sorted keys (O(log n) access) | | unordered_map | Key-value pairs, fastest lookup O(1) average | | set | Unique sorted elements |

11. What is a template? Why is it useful?

Templates let you write type-independent code. The compiler generates a specialised version for each type used.

template <typename T>
T maxOf(T a, T b) { return (a > b) ? a : b; }
// Works for int, double, string — anything with operator>

Tricky Output Questions

These are the questions that separate candidates who understand C++ from those who memorised it.

12. What is the output?

int x = 5;
int y = x++ + ++x;
cout << y;

Answer: Undefined behaviour in C++ (modifying x twice between sequence points). Tell the interviewer exactly this — it shows you know the standard, not just a guess.

13. What is the size of an empty class in C++?

1 byte. The standard requires distinct objects to have distinct addresses, so an empty class must occupy at least one byte. The interviewer is checking whether you know this — many freshers say 0.


Commonly Missed Topics

Constructor and destructor order

In inheritance, constructors execute base → derived. Destructors execute derived → base. Gets reversed from what many candidates assume.

static members

A static member belongs to the class, not any instance. All objects share it. A static function can only access static data.

Copy constructor vs assignment operator

The copy constructor creates a new object from an existing one (MyClass b = a). The assignment operator copies into an already-existing object (b = a). The Rule of Three: if you define a destructor, copy constructor, or copy assignment operator, you almost certainly need all three.


How to Stand Out

Most freshers answer these questions correctly but mechanically. What separates a strong C++ candidate:

  1. Give a "why" — not just "virtual functions enable polymorphism" but "without virtual, the vtable isn't consulted and you lose runtime dispatch."
  2. Write code — when asked about overloading or templates, offer to write a 4-line example. It signals you've actually used the concept.
  3. Admit what you don't know — "I know the rule, but I'd verify the exact behaviour in the standard before writing production code" is a better answer than a confident wrong one.

For more practice on framing technical answers the way interviewers score them, check out the CareerClutch features page — the AI mock interview gives you per-answer feedback on clarity, structure, and depth.

A strong C++ foundation isn't just about clearing this round — it underlies systems programming, embedded work, and high-performance backends. Worth knowing cold.