0% found this document useful (0 votes)
3 views3 pages

C++ Cheat Sheet

This C++ Programming Cheat Sheet provides essential concepts including basic structure, input/output, data types, operators, conditions, loops, arrays, strings, functions, and classes. It also includes bonus essentials and practice exercises for various programming concepts. The cheat sheet aims to cover the most important 20% of C++ that will help in understanding 80% of the language's functionality.

Uploaded by

hussainyousuf819
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

C++ Cheat Sheet

This C++ Programming Cheat Sheet provides essential concepts including basic structure, input/output, data types, operators, conditions, loops, arrays, strings, functions, and classes. It also includes bonus essentials and practice exercises for various programming concepts. The cheat sheet aims to cover the most important 20% of C++ that will help in understanding 80% of the language's functionality.

Uploaded by

hussainyousuf819
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Programming Cheat Sheet: The 20% That Covers 80%

1. Basic Structure
#include <iostream>
using namespace std;

int main() {
// Your code here
return 0;
}

2. Input & Output


int a;
cin >> a; // Input
cout << a << endl; // Output

3. Data Types & Variables


int num = 10;
float pi = 3.14;
char ch = 'A';
string name = "Yousuf";
bool isOn = true;

4. Operators
+ - * / % // Arithmetic
== != < > <= >= // Comparison
&& || ! // Logical
= += -= *= /= // Assignment

5. Conditions (if, else)


if (a > b) {
cout << "A is greater";
} else if (a == b) {
cout << "Equal";
} else {
cout << "B is greater";
}

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

10. Classes & Objects (OOP)


class Student {
public:
string name;
int age;

void display() {
cout << name << " " << age;
}
};

int main() {
Student s;
s.name = "Ravi";
s.age = 21;
s.display();
}

11. Bonus Essentials


#include <cmath> // pow(), sqrt(), etc.
#include <vector> // dynamic arrays
#include <algorithm> // sort(), max(), min()
C++ Programming Cheat Sheet: The 20% That Covers 80%

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 |

You might also like