C++ Programming Complete Tutorial
Beginner to Advanced

C++ Programming Language Tutorial

Master C++ programming from basic syntax to advanced Object-Oriented Programming (OOP), STL, and modern C++ features with practical examples.

Object-Oriented

Learn OOP concepts

STL Included

Standard Template Library

Modern C++

C++11/14/17/20 Features

1. Introduction to C++ Programming

C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". It has imperative, object-oriented and generic programming features, while also providing facilities for low-level memory manipulation.

History of C++
  • 1979: Bjarne Stroustrup begins work on "C with Classes"
  • 1983: Renamed to C++
  • 1985: First commercial release
  • 1998: First ISO standard (C++98)
  • 2011: Major update (C++11)
  • 2014, 2017, 2020: Subsequent updates
Why Learn C++?
  • High performance and efficiency
  • Object-Oriented Programming
  • Standard Template Library (STL)
  • Used in game development, system software
  • Foundation for understanding other languages
  • Cross-platform development

First C++ Program

Every C++ program must have a main() function. Here's the traditional "Hello, World!" program:

hello.cpp
#include <iostream>
using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

2. Basic Syntax and Structure

C++ programs are composed of various tokens including keywords, identifiers, literals, operators, and punctuators.

Component Description Example
Preprocessor Directives Instructions for the preprocessor #include <iostream>
Namespace Prevents naming conflicts using namespace std;
Functions Blocks of code that perform tasks int main() { ... }
Variables Named storage locations int count = 10;
Statements Instructions that perform actions cout << "Hello";
Comments Explanatory text ignored by compiler // Single line comment
Best Practice: Always include comments to explain complex logic. Use meaningful variable names and follow consistent indentation.

3. Running C++ Programs

Windows Setup

Using Visual Studio (Recommended for Windows):
  1. Download Visual Studio Community Edition
  2. Install "Desktop development with C++" workload
  3. Create a new C++ Console Application project
  4. Write code and press F5 to run
Using MinGW (Alternative)
# Install MinGW
# Add to PATH: C:\MinGW\bin
# Compile: g++ hello.cpp -o hello.exe
# Run: hello.exe
Linux Setup
# Install g++
sudo apt install g++

# Compile
g++ hello.cpp -o hello

# Run
./hello

30-Day C++ Learning Roadmap

1-7
Week 1: C++ Fundamentals

Syntax, Data Types, Operators, Basic I/O

8-14
Week 2: Control Flow & Functions

Conditionals, Loops, Functions, Arrays

15-21
Week 3: Object-Oriented Programming

Classes, Objects, Inheritance, Polymorphism

22-30
Week 4: Advanced Topics

STL, File Handling, Modern C++

4. Variables and Data Types

C++ supports various data types including primitive types, derived types, and user-defined types.

Variables Example
#include <iostream>
using namespace std;

int main() {
    // Primitive data types
    int age = 25;
    float salary = 45000.50f;
    double pi = 3.1415926535;
    char grade = 'A';
    bool isEmployed = true;
    
    // Auto keyword (C++11)
    auto score = 95.5; // double
    
    // Display values
    cout << "Age: " << age << endl;
    cout << "Salary: " << salary << endl;
    cout << "Grade: " << grade << endl;
    cout << "Is Employed: " << boolalpha << isEmployed << endl;
    
    return 0;
}
Data Type Size (Bytes) Range Example
int4-231 to 231-1int x = 10;
float4±3.4e-38 to ±3.4e38float f = 3.14f;
double8±1.7e-308 to ±1.7e308double d = 3.14159;
char1-128 to 127char c = 'A';
bool1true/falsebool flag = true;
wchar_t20 to 65,535wchar_t wc = L'A';