"This is CPP tutorial and this is for learning CPP"
By Harry
09/02/2025
Welcome to this comprehensive C++ programming tutorial! Whether you're a complete beginner or seeking to advance your C++ skills, this guide will walk you through the basics and help you dive into more advanced concepts as you progress.
C++ is an extension of the C programming language, known for its high performance and support for object-oriented programming. It is widely used in system programming, game development, and large-scale applications.
Before you start coding, you'll need to set up your development environment. Here’s how:
g++ --version in your terminal or command prompt.Now that your environment is set up, let’s start with the basics. In this section, we'll cover:
#include <iostream>
 
int main() {
    int age = 25;
    double height = 5.9;
    char initial = 'A';
 
    std::cout << "Age: " << age << ", Height: " << height << ", Initial: " << initial << std::endl;
    return 0;
}#include <iostream>
 
int main() {
    int age = 20;
 
    if (age >= 18) {
        std::cout << "You are an adult." << std::endl;
    } else {
        std::cout << "You are a minor." << std::endl;
    }
 
    for (int i = 0; i < 5; i++) {
        std::cout << "Count: " << i << std::endl;
    }
 
    return 0;
}#include <iostream>
 
void greet(std::string name) {
    std::cout << "Hello, " << name << "!" << std::endl;
}
 
int main() {
    greet("Alice");
    return 0;
}After mastering the basics, it’s time to explore more advanced features of C++:
#include <iostream>
 
class Dog {
public:
    std::string name;
    std::string breed;
 
    void bark() {
        std::cout << name << " says Woof!" << std::endl;
    }
};
 
int main() {
    Dog dog;
    dog.name = "Buddy";
    dog.breed = "Golden Retriever";
    dog.bark();
 
    return 0;
}#include <iostream>
 
int main() {
    int x = 10;
    int *ptr = &x;  // Pointer to x
 
    std::cout << "Value of x: " << x << std::endl;
    std::cout << "Address of x: " << ptr << std::endl;
    std::cout << "Value at address: " << *ptr << std::endl;
 
    return 0;
}#include <iostream>
#include <vector>
 
int main() {
    std::vector<int> numbers = {1, 2, 3, 4, 5};
 
    for (int num : numbers) {
        std::cout << num << " ";
    }
 
    std::cout << std::endl;
    return 0;
}Once you’re comfortable with intermediate topics, it’s time to dive into more advanced concepts:
#include <iostream>
 
class Animal {
public:
    virtual void sound() {
        std::cout << "Some generic animal sound." << std::endl;
    }
};
 
class Dog : public Animal {
public:
    void sound() override {
        std::cout << "Woof!" << std::endl;
    }
};
 
int main() {
    Animal *animal = new Dog();
    animal->sound();
 
    delete animal;
    return 0;
}#include <iostream>
 
class Complex {
public:
    int real, imag;
 
    Complex(int r = 0, int i = 0) : real(r), imag(i) {}
 
    Complex operator + (const Complex &obj) {
        return Complex(real + obj.real, imag + obj.imag);
    }
 
    void display() {
        std::cout << real << " + " << imag << "i" << std::endl;
    }
};
 
int main() {
    Complex c1(3, 4), c2(1, 2);
    Complex c3 = c1 + c2;
 
    c3.display();
    return 0;
}#include <iostream>
 
int main() {
    try {
        int a = 10, b = 0;
        if (b == 0)
            throw "Division by zero error!";
        std::cout << a / b << std::endl;
    } catch (const char* msg) {
        std::cerr << msg << std::endl;
    }
 
    return 0;
}Congratulations on completing this C++ tutorial! You’ve learned everything from the basics to advanced topics like inheritance and operator overloading. C++ is a powerful language, and with continued practice, you can build high-performance applications.
Happy coding!