Skip to the page

Languages · 20 concepts

C++

C++ as campus language and coding rounds ask it: pointers and memory, classes and virtual functions, templates, and the STL containers that coding tests use.

Asked in these mock interviews

Part 1 · 3 concepts

Basics for coding rounds

  1. 01

    Compiling, headers and namespaces

    g++ turns your .cpp file into a program in two steps: compile, then link. Headers bring in declarations, and namespaces keep names apart, so know what std:: and using…

  2. 02

    cin, cout, fast input and time limits

    Coding tests read large inputs and have a time limit. Know how cin and cout behave, the two lines that make them fast, and how to check your idea against the limits…

  3. 03

    Integer types, operators and overflow

    An int holds about 2.1 x 10^9. Many Wrong Answers in coding tests come from overflow, from unsigned sizes, or from changing one variable twice in one line.

Part 2 · 4 concepts

Pointers and memory

  1. 04

    Pointers, references and passing arguments

    A pointer holds an address; a reference is another name for an existing variable. Pass by value gives the function a copy; pass by pointer or by reference lets it…

  2. 05

    Arrays, C strings and std::string

    An array name turns into a pointer to its first element, which is why sizeof changes inside a function. A C string ends with '\0'; std::string manages its own memory…

  3. 06

    Stack, heap, new and delete

    Local variables live on the stack and die when the function returns. new puts an object on the heap, where it stays until you delete it. Most memory bugs come from…

  4. 07

    Segmentation faults and finding memory bugs

    A segmentation fault means the program touched memory it may not use. In coding tests it is usually an index past the end, a null or dangling pointer, or a stack that…

Part 3 · 6 concepts

Classes and objects

  1. 08

    Classes, structs and access

    A class keeps data and the functions that keep it valid together. In C++ the only difference between class and struct is the default access.

  2. 09

    Constructors, destructors and their order

    A constructor sets up an object and a destructor cleans it up. Bases are built first and destroyed last, and members follow the order in which they are declared.

  3. 10

    Copy constructor, deep copy and the rule of three

    The compiler's copy copies every member. For a raw pointer that is a shallow copy: two objects share one block and both delete it. A class that owns a resource needs…

  4. 11

    RAII and smart pointers

    RAII ties a resource to an object: the constructor gets it and the destructor gives it back, so cleanup happens even on an early return or an exception. Smart pointers…

  5. 12

    static members and static locals

    static means one copy with a long life. A static data member is shared by every object of the class, and a static local variable keeps its value between calls.

  6. 13

    Function and operator overloading

    Overloading gives one name several versions with different parameters; the compiler picks one from the argument types. Operator overloading lets your own types use +…

Part 4 · 3 concepts

Inheritance and polymorphism

  1. 14

    Inheritance, virtual functions and the vtable

    Public inheritance means "is a". A virtual function called through a base pointer or reference runs the version of the real object, chosen at runtime, usually through a…

  2. 15

    Pure virtual functions and abstract classes

    A pure virtual function, written = 0, must be overridden. A class with one is abstract: you cannot create it, only the classes that implement every pure virtual…

  3. 16

    Multiple inheritance and the diamond problem

    C++ lets a class have several base classes. When two bases share a common base, the derived class gets two copies of it, unless the inheritance is virtual.

Part 5 · 4 concepts

Templates and the STL

  1. 17

    Function and class templates

    A template is a pattern for functions or classes. The compiler makes a separate version for each type you use, which is how vector<int> and vector<string> both work.

  2. 18

    vector, deque, stack, queue and priority_queue

    vector is the default container in coding tests. stack, queue and priority_queue are adaptors built on a vector or a deque. Know the cost of each operation and the…

  3. 19

    map, unordered_map and set

    map and set keep their keys sorted in a balanced tree, with O(log n) operations. unordered_map uses a hash table: O(1) on average, but with no order. Choose by whether…

  4. 20

    Iterators, sort and comparators

    Iterators walk through any container with the same code. sort orders a range in O(n log n), and a comparator changes the order, but it must be a strict "less than".

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview