C++ Intermediate Cheatsheet
C++ Intermediate Cheatsheet (Pointers, STL, Memory, Structs)
Take your C++ skills to the next level with this intermediate cheatsheet. Master pointers, memory, STL, and core concepts used in real-world coding and interviews.
If you haven’t covered basics, start with the C++ Basics Cheatsheet first.
Quick Navigation
1. Pointers (Core C++ Concept)
Direct access to memory addresses.
01int x = 10;02int* p = &x;0304cout << *p; // 10
Key Concepts
&xgives the address of a variable*pgives the value at that address- Pointers store memory addresses
Why Pointers Matter
- Memory control
- Dynamic allocation
- Used in arrays, functions, data structures
Interview must-know topic.
2. References (Cleaner Alternative to Pointers)
Aliases without pointer syntax.
01int x = 10;02int& ref = x;0304ref = 20;05cout << x; // 20
Key Insight
- Reference = alias of a variable
- No separate memory needed
- Common for pass-by-reference
3. Memory Management (new & delete)
Manual heap allocation essentials.
01int* p = new int(5);02cout << *p;0304delete p;
Important Rules
- Always delete allocated memory
- Avoid memory leaks
- Don’t use freed pointers
Common Mistake
01int* p = new int(10);02// forgot delete → memory leak
4. Structures (struct)
Group related data simply.
01struct Student {02 string name;03 int age;04};0506Student s1 = {"Corwin", 21};07cout << s1.name;
Use Case
- Group related data
- Simple alternative to classes
5. Vectors (Dynamic Arrays)
Flexible and safer arrays.
01#include <vector>0203vector<int> v = {1,2,3};04v.push_back(4);0506cout << v[0]; // 1
Why Vectors?
- Dynamic size
- Easy to use
- Safer than arrays
Useful Operations
v.pop_back()v.size()v.clear()
6. Strings (Advanced Operations)
Practical string methods for real work.
01string s = "hello";02s += " world";0304cout << s.substr(0, 5); // hello
Common Functions
length()substr()find()
7. STL Algorithms (Power Feature)
Write less, do more with optimized algorithms.
01#include <algorithm>02#include <vector>0304vector<int> v = {3,1,2};0506sort(v.begin(), v.end());
More Examples
01reverse(v.begin(), v.end());
STL saves time, stays optimized, and is widely used in interviews.
8. Common Mistakes (Intermediate Level)
Avoid undefined behavior and runtime crashes.
Dangling Pointer
01int* p = new int(5);02delete p;03cout << *p; // Undefined behavior
Wrong Reference Usage
01int& ref; // Error (must initialize)
Vector Out of Bounds
01vector<int> v = {1,2,3};02cout << v[5]; // Error
9. Quick Practice (Test Yourself)
Run these to build confidence.
Q1
01int x = 10;02int* p = &x;03cout << *p;
Answer: 10
Q2
01vector<int> v = {1,2};02v.push_back(3);03cout << v.size();
Answer: 3
Q3
01string s = "abc";02cout << s[1];
Answer: b
Pro Tip
Run these in an editor and tweak the values. Active practice builds memory faster than passive reading.
Interview Focus (Important)
Topics interviewers expect you to know.
Must Know
- Pointer basics
- Reference vs pointer
- Vector vs array
- Memory allocation
Common Questions
- What is a dangling pointer?
- Why use vectors over arrays?
- Difference between stack & heap?
What’s Next
Move toward interview-ready depth.
Next Step: C++ Interview Cheatsheet
Recursion, time complexity, patterns, and edge cases to become job-ready.
Explore Interview TopicsHow to Use This Page
- Learn → read + run code
- Revise → scan quickly
- Practice → solve problems
- Repeat → build memory
FAQs
Are pointers hard to learn?
Initially yes — but practice makes them easy.
Should I memorize STL?
No — understand patterns and usage instead.
Is this enough for interviews?
You need practice + patterns + depth. This is a strong start.
Product Insight (For You)
This page builds serious learner trust.
High-Value Topics
Pointers, STL, and memory in one place.
Interview Ready
Focused on common interview concepts.
Actionable
Practice prompts built in.