C++ Basics Cheatsheet
C++ Basics Cheatsheet (Syntax + Examples for Beginners)
Learn C++ fundamentals fast with this beginner-friendly cheatsheet. Master syntax, understand core concepts, and start writing code immediately. Use this page to revise quickly, then move to advanced topics when ready.
Quick Navigation
1. Variables & Data Types
Core building blocks of every C++ program.
01int age = 25;02float price = 10.5;03double pi = 3.14159;04char grade = 'A';05string name = "Schoolabe";06bool isActive = true;
Key Notes
intstores whole numbersfloatanddoublestore decimals (double is more precise)charstores a single characterstringstores textboolstores true or false
Interview Insight
The difference between float and double is a common interview question.
2. Input / Output (cin & cout)
Take input and print output with streams.
01#include <iostream>02using namespace std;0304int main() {05 int x;06 cin >> x;07 cout << "Value: " << x;08}
Key Notes
cintakes input from the usercoutprints output to the screen<<sends data to output>>receives input
These appear in almost every C++ program.
3. Operators & Expressions
Use operators to build expressions and calculations.
01int a = 10, b = 5;0203cout << (a + b); // 1504cout << (a - b); // 505cout << (a * b); // 5006cout << (a / b); // 207cout << (a % b); // 0
Common Trap
01int x = 5 / 2; // Output = 2
Integer division removes decimals. Use 5.0 / 2 to get 2.5.
4. Control Flow
Make decisions and repeat logic.
If-Else
01if (age >= 18) {02 cout << "Adult";03} else {04 cout << "Minor";05}
For Loop
01for (int i = 0; i < 5; i++) {02 cout << i;03}
While Loop
01int i = 0;02while (i < 5) {03 cout << i;04 i++;05}
Interview Tip
Know when to use each loop and how they differ in structure and readability.
5. Functions
Write reusable logic and keep code clean.
01int add(int a, int b) {02 return a + b;03}0405// Usage06cout << add(3, 4); // 7
Why Functions?
- Reusability without copy-paste
- Cleaner, more readable code
- Better structure for teamwork
6. Arrays & Strings
Store multiple values and work with text.
Arrays
01int arr[3] = {1, 2, 3};02cout << arr[0]; // 1
Strings
01#include <string>0203string name = "Schoolabe";04cout << name.length();
Key Notes
- Array indexing starts from 0
- Arrays have fixed size
- Strings are more flexible for text
7. Common Mistakes (Beginner Traps)
Avoid these to save time and frustration.
Uninitialized Variable
01int x;02cout << x; // Garbage value
Assignment vs Comparison
01if (a = 5) // WRONG02if (a == 5) // CORRECT
Missing Semicolon
01int a = 10 // Error
8. Quick Practice (Test Yourself)
Try before checking answers.
Q1
01int x = 10;02cout << x % 4;
Answer: 2
Q2
01for (int i = 1; i <= 3; i++) {02 cout << i;03}
Output: 123
Q3
01int a = 5;02if (a > 3) {03 cout << "Yes";04}
Output: Yes
Pro Tip
Run these in an editor and modify the values. Active practice builds confidence faster than passive reading.
What's Next
Move from quick revision to real C++ power.
Next Step: C++ Intermediate Cheatsheet
Pointers, references, vectors, and memory basics to level up from beginner to job-ready.
Open Intermediate CheatsheetWhen to Use This Page
- Before coding for quick revision
- During coding as a syntax reference
- After learning to reinforce fundamentals
- Before interviews for rapid recall
Keep Improving
Small habits that make a big difference.
- Add your own notes while revising
- Highlight weak areas and revisit weekly
- Practice consistently to build speed
FAQs
Is this enough to learn C++?
No. This cheatsheet is for quick revision. Use the full course for deeper learning.
How long should I spend here?
10 to 15 minutes per session plus practice is enough for most learners.
What should I do next?
Move to the intermediate cheatsheet and practice problems to build real C++ fluency.
Product Insight (For You)
This page is optimized for speed and action.
Searchable
SEO entry point for C++ beginners.
Scannable
Short sections for fast revision.
Actionable
Practice prompts built in.