C++ Notes - Beginner to Advanced
1. Introduction to C++
C++ is a general-purpose programming language developed by Bjarne Stroustrup as an extension
of C. It supports both procedural and object-oriented paradigms.
2. Structure of a C++ Program
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
3. Data Types
Basic types include:
- int: 1, -10
- float: 3.14
- double: 3.14159
- char: 'a'
- bool: true/false
- string: "text"
4. Variables & Constants
int age = 25;
const float PI = 3.14; // constant value
5. Operators
Arithmetic: +, -, *, /, %
Page 1
C++ Notes - Beginner to Advanced
Comparison: ==, !=, >, <
Logical: &&, ||, !
6. Control Structures
If-Else:
if (x > 0) {
// do something
} else {
// do something else
}
Loops:
for, while, do-while
7. Functions
int add(int a, int b) {
return a + b;
}
8. Arrays & Strings
int arr[5] = {1, 2, 3, 4, 5};
string name = "C++";
9. Object-Oriented Programming
class Car {
public:
string brand;
void drive() {
cout << "Driving...";
Page 2
C++ Notes - Beginner to Advanced
}
};
10. Pointers & References
int x = 10;
int *ptr = &x;
int &ref = x;
11. File Handling
#include <fstream>
ofstream file("data.txt");
file << "Hello!";
12. Templates
template <typename T>
T add(T a, T b) {
return a + b;
}
13. Exception Handling
try {
// risky code
} catch (exception &e) {
cout << e.what();
}
14. STL (Standard Template Library)
Includes containers like vector, map, set, etc.
Page 3
C++ Notes - Beginner to Advanced
vector<int> v = {1, 2, 3};
15. Advanced Topics
- Lambda functions
- Smart pointers
- Move semantics
- Multithreading
Page 4