C++ Cheat Sheet
C++ Cheat Sheet
1. Basic Structure
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}
4. Operators
+ - * / % // Arithmetic
== != < > <= >= // Comparison
&& || ! // Logical
= += -= *= /= // Assignment
6. Loops
// For Loop
for (int i = 0; i < 5; i++) {
cout << i;
}
// While Loop
int i = 0;
while (i < 5) {
cout << i;
C++ Programming Cheat Sheet: The 20% That Covers 80%
i++;
}
7. Arrays
int arr[5] = {10, 20, 30, 40, 50};
for (int i = 0; i < 5; i++) {
cout << arr[i];
}
8. Strings
string name = "Ali";
cout << name[0]; // Access character
cout << name.length(); // Length of string
9. Functions
int add(int x, int y) {
return x + y;
}
int main() {
cout << add(5, 6);
}
void display() {
cout << name << " " << age;
}
};
int main() {
Student s;
s.name = "Ravi";
s.age = 21;
s.display();
}
Practice Exercises
| Program Type | Practice Idea |
|----------------------|----------------------------------------|
| Input/Output | Name, age, add two numbers |
| If-else | Even or Odd, Greatest of 3 numbers |
| Loops | Print 1 to N, factorial, sum of digits |
| Arrays | Find max, reverse array, search |
| Strings | Palindrome check, count vowels |
| Functions | Prime check, calculator functions |
| Class/Object | Student info system |