0% found this document useful (0 votes)
2 views

cpp_cheatsheet

This C++ cheat sheet provides a quick reference for basic programming concepts including data types, conditionals, loops, functions, arrays, pointers, classes, inheritance, and file handling. It includes code snippets demonstrating each concept, such as printing 'Hello, World!', using conditionals, and defining classes. The document serves as a concise guide for beginners and intermediate programmers to understand and implement C++ syntax and features.

Uploaded by

arsalaan272158
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

cpp_cheatsheet

This C++ cheat sheet provides a quick reference for basic programming concepts including data types, conditionals, loops, functions, arrays, pointers, classes, inheritance, and file handling. It includes code snippets demonstrating each concept, such as printing 'Hello, World!', using conditionals, and defining classes. The document serves as a concise guide for beginners and intermediate programmers to understand and implement C++ syntax and features.

Uploaded by

arsalaan272158
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Cheat Sheet

1. Basics
#include<iostream>
using namespace std;

int main() {
cout << "Hello, World!" << endl;
return 0;
}

2. Data Types & Variables


int a = 10;
float b = 5.5;
double c = 10.99;
bool d = true;
char e = 'A';
string f = "Hello";

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;
}

cout << add(5, 10);

6. Arrays & Vectors


int arr[] = {1, 2, 3, 4, 5};
vector<int> vec = {1, 2, 3, 4, 5};
vec.push_back(6);

7. Pointers
int x = 10;
int *ptr = &x;
cout << *ptr;

8. Classes & Objects


class Car {
public:
string brand;
Car(string b) { brand = b; }
};

Car myCar("Tesla");
cout << myCar.brand;

9. Inheritance
class Animal {
public:
void speak() { cout << "Animal speaks"; }
};

class Dog : public Animal {};


Dog d;
d.speak();

10. File Handling


#include<fstream>
ofstream myfile("test.txt");
myfile << "Hello File";
myfile.close();

Let me know if you need additional details!

You might also like