1. Introduction to C++

C++ is a powerful programming language created as an extension of C. It supports both procedural programming and Object-Oriented Programming (OOP).

C++ is widely used in game engines, operating systems, desktop applications, browsers, and performance-critical systems.

Learning C++ helps you understand memory management, performance optimization, and advanced programming techniques.

2. Basic Structure of a C++ Program

C++ uses the iostream library for input and output.

#include <iostream> using namespace std; int main() { cout << "Hello World"; return 0; }

cout prints output and return 0 ends the program successfully.

3. Variables in C++

Variables store data values. Each variable must have a defined data type.

int age = 21; float height = 5.8; char grade = 'A'; bool isPassed = true;

4. Data Types

Common data types include:

int → Whole numbers

float/double → Decimal numbers

char → Single characters

bool → true or false

5. Taking User Input

int number; cin >> number; cout << "You entered: " << number;

6. Operators in C++

C++ supports arithmetic, relational, logical, and assignment operators.

int a = 10, b = 5; cout << a + b; // Addition cout << a > b; // Comparison

7. Conditions (Decision Making)

Conditions allow a program to make decisions based on whether a statement is true or false.

C++ uses if, else if, and else statements to control the flow of execution.

Comparison operators like ==, !=, >, <, >=, <= are used inside conditions.

int age = 18; if(age >= 18){ cout << "Adult"; }else{ cout << "Minor"; }

Here, the program checks if age is greater than or equal to 18. If true, it prints "Adult", otherwise "Minor".

8. Loops

Loops are used to repeat a block of code multiple times.

C++ mainly provides three types of loops: for loop, while loop, and do-while loop.

The for loop is commonly used when the number of repetitions is known.

for(int i=1;i<=5;i++){ cout << i << " "; }

This loop starts from 1 and runs until 5, printing numbers in sequence.

9. Functions

Functions are reusable blocks of code that perform a specific task.

They help organize programs and avoid repeating the same code multiple times.

A function has a return type, name, and parameters.

int add(int a, int b){ return a + b; }

This function takes two numbers and returns their sum. Functions are called inside main().

10. Arrays

Arrays store multiple values of the same data type in a single variable.

Each value is accessed using an index number, starting from 0.

int numbers[5] = {1,2,3,4,5}; cout << numbers[0]; // prints 1

Arrays are useful when handling lists of data like marks, scores, or temperatures.

11. Strings in C++

Strings are used to store text. C++ provides the string data type from the standard library.

You must include the <string> header file to use strings.

#include <string> string name = "Kafe"; cout << name;

Strings support many operations like concatenation, length checking, and comparison.

12. Object-Oriented Programming

C++ supports Object-Oriented Programming, which allows programs to be organized using objects and classes.

Main OOP concepts include:

Encapsulation → Wrapping data and functions together

Inheritance → One class acquiring properties of another

Polymorphism → Same function behaving differently

Abstraction → Hiding internal details

13. Classes & Objects

A class is a blueprint for creating objects. An object is an instance of a class.

Classes contain variables (data members) and functions (member functions).

class Car { public: string brand; int year; }; int main(){ Car c1; c1.brand = "BMW"; c1.year = 2022; }

Here, Car is a class and c1 is an object. Objects allow us to model real-world entities in programs.