C++ Revision Notes with Flowcharts & Memory Diagrams
References in C++
A reference is an alias for another variable using '&'. Must be initialized, cannot be null, cannot change target.
KEY TAKEAWAYS:
- Pass by value vs pass by reference
- Use 'const' to prevent modification
Memory Diagram: Draw x, y, z pointing to same memory when reference is assigned.
Address & Dereference Operators
& gives address of a variable, * accesses value at an address.
Memory Diagram: Show variable with name, address, and value.
Pointers
Pointers store addresses. A pointer must point to valid memory or NULL.
Tip: const int &q = 5; works for literals.
Memory Diagram: Show pointer box holding address pointing to another variable.
Strings
Use string.find() to search occurrences.
Flowchart: Input string -> find() -> loop until no more occurrences.
Classes vs Structures
Class members are private by default; struct members are public.
Flowchart: Class/Struct -> Members -> Access Control.
Page 1
C++ Revision Notes with Flowcharts & Memory Diagrams
Unions
All members share same memory; size = largest member.
Memory Diagram: Single memory block shared by int, char, double.
Structure Alignment & Padding
Padding aligns data for CPU efficiency.
Memory Diagram: Show padding bytes between members.
Templates
Write code once, use for any type.
Flowchart: Compiler expands templates for required types.
Exception Handling
try -> throw -> catch -> stack unwinding.
Flowchart: Code block -> exception? -> catch block or terminate.
STL & Iterators
Containers, Algorithms, Iterators.
Diagram: Show vector/list with iterator moving through elements.
Memory Allocation Types
Static (compile time), Automatic (stack), Dynamic (heap).
Memory Diagram: Show stack vs heap boxes.
Lambda & Closures
Page 2
C++ Revision Notes with Flowcharts & Memory Diagrams
Anonymous functions capturing variables by [&] or [=].
Flowchart: Lambda defined -> captures -> executes.
Inline Functions
Expands code inline to reduce function call overhead.
Diagram: Function code copied at call site.
Operator Overloading
You can redefine operators like +, ++ for user-defined types.
Flowchart: Operator call -> overloaded function executed.
New vs malloc()
new is operator, calls constructor; malloc is function, no constructor.
Memory Diagram: Heap memory allocation shown.
Page 3