1. Types and the type system
- Static typing; conversions are explicit (
static_cast,int(x)) or implicit when no data is lost. - Virtually no
charpitfalls in modern code: avoid arrays, usestd::string. - Integer types:
int,long,long long,unsigned,size_t;sizeofis compile-time in bytes.
2. const correctness
const x— bind once, can’t change.const int* p— pointer to const int (can movep, 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.constmethods,constmember 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.
| Reference | Pointer |
|---|---|
| alias, must init | can be null, can move |
| safer, cleaner | more flexible |
| re-bind impossible | fine to reassign |
4. auto & structured bindings
auto x = 5;type is deduced; no implicit narrowing on init.autodrops references/const by default (auto&keeps them).auto [a, b] = pair/mapEntry;— structured bindings (C++17).decltypegives 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;
usingbrings symbols in locally. - Headers contain declarations,
.cppfiles definitions; include guards or#pragma once.
6. Interview checkpoint
- const forms (pointer to const vs const pointer).
- References — lifetime, no null.
- auto/structured bindings.
sizeofcompile-time vs runtime.- Enum vs enum class difference.
Premium Content
Unlock Part 1: Language Foundation & Modern Basics and all premium lessons with a subscription.
All premium lessons
Ad-free experience
Priority support
From ₹199.99/year — See plans