C++ Detailed Notes
C++ Detailed Notes
1. Introduction to C++
C++ is a powerful, high-performance programming language created by Bjarne Stroustrup in 1985.
It is an extension of the C language with features that support object-oriented programming (OOP).
C++ is used in systems programming, game development, real-time simulations, and more.
int main() {
cout << "Hello, World!"; // Output statement
return 0; // Indicates successful execution
}
3. Data Types
C++ supports various data types:
Page 1
C++ Notes - Beginner to Advanced
5. Operators
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: && (AND), || (OR), ! (NOT)
- Assignment: =, +=, -=, *=
6. Control Structures
- if, if-else: Used to execute code blocks conditionally.
Example:
if (x > 0) {
cout << "Positive";
} else {
cout << "Non-positive";
}
- Loops:
for (int i = 0; i < 5; i++) {
cout << i;
}
while (condition) {
// loop body
}
Page 2
C++ Notes - Beginner to Advanced
do {
// body
} while (condition);
7. Functions
Functions allow code reuse.
Example:
int sum(int a, int b) {
return a + b;
}
int main() {
cout << sum(3, 4);
return 0;
}
Page 3
C++ Notes - Beginner to Advanced
Example:
class Person {
public:
string name;
void greet() {
cout << "Hello " << name;
}
};
ofstream file("data.txt");
file << "Writing to file";
ifstream file("data.txt");
string content;
file >> content;
12. Templates
Used to write generic functions or classes.
template <typename T>
T max(T a, T b) {
Page 4
C++ Notes - Beginner to Advanced
return (a > b) ? a : b;
}
These notes provide a solid foundation for mastering C++ step-by-step with real understanding.
Page 5