Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Roadmaps › Languages

C++ Roadmap

Master C++ for DSA and competitive programming.

Level: Beginner → Intermediate · Duration: 2–3 months

Step 1: Basics

Write, compile and run your first programs.

C++ is a fast, compiled language that gives you close control over memory. It is the most popular language for competitive programming and is widely used in DSA preparation, games and systems. Begin by writing, compiling and running small programs until the syntax feels natural.

  • Setting up a compiler (g++) and an editor
  • Structure of a C++ program and main()
  • Input/output with cin and cout
  • Variables, types, conditions, loops and functions

Resources: ▶ C++ Full Course & DSA · C++ documentation

I/O & data types

cin / cout, int, long long, double, char, bool.

cin and cout handle input and output. Choosing the right data type matters: int overflows above about 2×10⁹, so use long long for big numbers.

  • cin, cout and endl vs "\n"
  • int, long long, double, char, bool
  • Integer limits and overflow
  • Type casting

Conditionals & loops

if/else, switch, for, while, do-while.

if/else and switch choose what runs; for, while and do-while repeat it. Nested loops are the base of many brute-force solutions.

  • if / else if / else
  • switch-case
  • for, while and do-while
  • break, continue and nested loops

Functions

Parameters, return values, pass by value vs reference.

Functions break programs into reusable pieces. Pass by reference (&) lets a function change the caller's variable and avoids copying large objects.

  • Declaring and defining functions
  • Pass by value vs pass by reference
  • Default arguments and overloading
  • Recursion basics

Header files & compilation

What #include does; compiling with g++.

Each .cpp file is compiled separately and then linked. Header files share declarations between files. Knowing this explains many confusing compiler and linker errors.

  • What #include does
  • Compiling and linking with g++
  • Compiler warnings (-Wall) and reading errors
  • #include <bits/stdc++.h> in competitive programming

Step 2: Arrays & Strings

Store and process collections of values.

Arrays store many values of the same type; std::string makes text easy to work with. Together they appear in most beginner and interview problems.

  • Static arrays and 2D arrays
  • std::string operations
  • Common array and string algorithms

Resources: Practice: Arrays problems · Practice: Strings problems

1D & 2D arrays

Traversal, matrices, passing arrays to functions.

Arrays have a fixed size and are indexed from 0. 2D arrays represent grids and matrices. Out-of-bounds access is undefined behaviour — a common source of crashes.

  • Declaring and initialising arrays
  • Traversal, sum, max and reverse
  • 2D arrays and matrix traversal
  • Passing arrays to functions

std::string

Concatenation, substr, find, getline.

std::string handles memory for you and comes with useful methods. Read full lines with getline.

  • length, substr, find, append, erase
  • Comparing and concatenating strings
  • getline and mixing it with cin
  • Character arithmetic (c - 'a')

Step 3: Pointers & References

Memory, dynamic allocation.

Pointers store memory addresses; references are aliases for existing variables. They are what make C++ fast and flexible — and also what makes it easy to write bugs, so learn them carefully.

  • Memory addresses and the & operator
  • Pointers and dereferencing
  • References
  • Dynamic memory and avoiding leaks

Resources: Notes: Pointers & References in C++

Pointers

Addresses, dereferencing, pointer arithmetic.

A pointer holds the address of another variable. Dereferencing (*p) reads or changes the value at that address.

  • Declaring pointers and nullptr
  • Dereferencing and pointer arithmetic
  • Pointers and arrays
  • Pointers to pointers

References

Aliases, const references in function parameters.

A reference is another name for an existing variable. const references let functions read big objects without copying them.

  • Declaring references
  • References vs pointers
  • const reference parameters

Dynamic memory

new / delete, memory leaks.

new allocates memory on the heap at runtime and delete frees it. Forgetting delete leaks memory; using memory after delete crashes.

  • Stack vs heap
  • new / delete and new[] / delete[]
  • Memory leaks and dangling pointers

Smart pointers (optional)

unique_ptr and shared_ptr.

Smart pointers free memory automatically when it is no longer needed, removing most manual delete calls in modern C++.

  • unique_ptr and make_unique
  • shared_ptr and reference counting
  • RAII

Step 4: OOP in C++

Classes, constructors, inheritance, virtual functions.

C++ supports object-oriented programming with classes, inheritance and virtual functions. OOP questions in interviews are often asked with C++ examples.

  • Classes and objects
  • Constructors and destructors
  • Inheritance and virtual functions
  • Operator overloading

Resources: Interview questions: OOP

Classes & constructors

Access specifiers, constructors, destructors.

Classes bundle data and functions. Constructors initialise objects and destructors clean them up when they go out of scope.

  • Access specifiers: public, private, protected
  • Constructors, initialiser lists and destructors
  • Copy constructor and assignment
  • this pointer and static members

Resources: Notes: Four Pillars of OOP

Inheritance & polymorphism

virtual functions and overriding.

Inheritance reuses code from a base class. virtual functions let a base-class pointer call the right derived-class method at runtime.

  • Public inheritance
  • virtual functions and override
  • Pure virtual functions and abstract classes
  • Virtual destructors

Operator overloading

Make your classes work with + , <<, ==.

You can define what +, ==, < or << mean for your own classes, so they work naturally with the standard library.

  • Overloading arithmetic and comparison operators
  • Overloading << for printing
  • operator< for sorting and sets

Templates (optional)

Write generic functions and classes.

Templates let you write a function or class once and use it with any type — the STL itself is built with templates.

  • Function templates
  • Class templates
  • Template specialisation basics

Step 5: STL

Containers, iterators and algorithms.

The Standard Template Library gives you fast, tested containers and algorithms. In DSA and competitive programming you will use it in almost every solution.

  • Containers: vector, set, map and more
  • Iterators
  • Algorithms: sort, binary search and others
  • Time complexity of each operation

Resources: Notes: C++ STL Cheat Sheet · C++ cheat sheet

vector, pair, string

The containers you will use the most.

vector is a dynamic array that grows as needed; pair groups two values. These are the most used containers.

  • push_back, size, clear, resize
  • Iterating with index, range-for and iterators
  • pair and sorting vectors of pairs
  • 2D vectors

set, map & unordered_map

Ordered vs hashed lookups.

set and map keep elements sorted (O(log n)); unordered_map uses hashing (average O(1)). Choose based on whether you need order.

  • insert, find, count, erase
  • Iterating in sorted order
  • lower_bound on sets and maps
  • unordered_map vs map trade-offs

stack, queue, priority_queue, deque

Adapters for common patterns.

These adapters give you LIFO, FIFO, heap and double-ended behaviour ready-made.

  • stack and queue operations
  • priority_queue as max-heap and min-heap
  • deque for sliding windows
  • Custom comparators

Algorithms

sort, lower_bound, next_permutation, accumulate.

The header has well-optimised functions for sorting, searching and more — learn them to write shorter, faster code.

  • sort with custom comparators
  • lower_bound, upper_bound, binary_search
  • reverse, max_element, accumulate
  • next_permutation and unique

Step 6: Competitive Programming

Practice on Codeforces / CodeChef / LeetCode.

Competitive programming means solving algorithmic problems under time limits. It sharpens problem-solving speed and is valued by product companies.

  • Reading problems and constraints
  • Choosing an algorithm from the constraints
  • Regular contest practice

Resources: ▶ Complete C++ Placement DSA Course · Codeforces · ▶ Competitive Programming Course

Fast I/O & templates

ios::sync_with_stdio(false), long long everywhere.

Fast input/output and a small starting template save time and avoid TLE on large inputs.

  • ios::sync_with_stdio(false) and cin.tie(nullptr)
  • Using long long by default
  • A reusable contest template
  • Avoiding endl in loops

Weekly contests

Compete every week and upsolve afterwards.

Contests train you to solve under pressure. Afterwards, always read editorials and solve what you missed.

  • Taking part every week
  • Upsolving and reading editorials
  • Tracking rating and weak topics

Resources: Codify weekly contests

Number theory (optional)

GCD, sieve, modular arithmetic.

Many contest problems need maths: primes, GCD and modular arithmetic for huge answers.

  • Sieve of Eratosthenes
  • GCD, LCM and modular arithmetic
  • Fast exponentiation (binary power)

Resources: Practice: Basics problems