cpp_cheatsheet
cpp_cheatsheet
1. Basics
#include<iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
3. Conditionals
if (a > b) {
cout << "A is greater";
} else {
cout << "B is greater";
}
4. Loops
for (int i = 0; i < 5; i++) {
cout << i << " ";
}
int j = 0;
while (j < 5) {
cout << j << " ";
j++;
}
5. Functions
int add(int x, int y) {
return x + y;
}
7. Pointers
int x = 10;
int *ptr = &x;
cout << *ptr;
Car myCar("Tesla");
cout << myCar.brand;
9. Inheritance
class Animal {
public:
void speak() { cout << "Animal speaks"; }
};