Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Part 1: Language Foundation & Modern Basics
C++

Part 1: Language Foundation & Modern Basics

Revise C++ types, const correctness, references, auto, structured bindings, and essential modern C++ language features.

1. Types and the type system

  • Static typing; conversions are explicit (static_cast, int(x)) or implicit when no data is lost.
  • Virtually no char pitfalls in modern code: avoid arrays, use std::string.
  • Integer types: int, long, long long, unsigned, size_t; sizeof is compile-time in bytes.

2. const correctness

  • const x — bind once, can’t change.
  • const int* p — pointer to const int (can move p, can’t write through it).
  • int* const p — const pointer to int (can write through, can’t re-point).
  • const int* const p — both const.
  • const methods, const member functions — promise not to modify.
int i = 5;
const int ci = 5;         // const qualifier
int const* p1 = &i;       // same as const int*
int* const p2 = &i;       // const pointer
*p2 = 6;                  // ok — pointed int is not const

3. References vs pointers

  • int& r = i; — alias, must be initialized, can never rebind.
  • References share the object, no &/* derefs at use site.
  • A reference to constant const int& r = 42; binds temporaries.
ReferencePointer
alias, must initcan be null, can move
safer, cleanermore flexible
re-bind impossiblefine to reassign

4. auto & structured bindings

  • auto x = 5; type is deduced; no implicit narrowing on init.
  • auto drops references/const by default (auto& keeps them).
  • auto [a, b] = pair/mapEntry; — structured bindings (C++17).
  • decltype gives exact type; decltype(auto) deduces exactly.
std::map<std::string, int> m;
for (const auto& [k, v] : m) { (void)k; (void)v; }

5. enum, namespaces, and headers

  • enum — integer constants.
  • enum class — scoped, strongly typed (C++11); pass by int conversion explicit.
  • Namespaces help avoid name clashes; using brings symbols in locally.
  • Headers contain declarations, .cpp files definitions; include guards or #pragma once.

6. Interview checkpoint

  • const forms (pointer to const vs const pointer).
  • References — lifetime, no null.
  • auto/structured bindings.
  • sizeof compile-time vs runtime.
  • Enum vs enum class difference.

My Private Notes

Notes are auto-saved locally to this device.