C++ Reference

Your complete guide to C++ programming language

🚀 What is C++?

C++ is a powerful, general-purpose programming language that supports object-oriented, procedural, and generic programming. It's widely used for system software, game development, and high-performance applications.


// Your first C++ program
#include <iostream>
using namespace std;

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

Output:

Hello, C++!

Key C++ Features

🎯

Object-Oriented

Classes, objects, inheritance, polymorphism

class Car {
public:
    void start() { cout << "Engine started!"; }
};

High Performance

Fast execution and memory control

int* ptr = new int(42);
delete ptr; // Manual memory management
🔧

Rich Library

Standard Template Library (STL)

#include <vector>
vector<int> numbers = {1, 2, 3, 4, 5};
🌐

Cross-Platform

Runs on Windows, Linux, macOS

// Same code works everywhere
cout << "Platform independent!";

🔹 Basic C++ Structure

Every C++ program is built upon a fundamental structure that includes necessary headers, a main function, and a return statement. The #include <iostream> directive brings in standard input/output functionalities. Execution begins at the int main() function, which serves as the program's entry point. The body of main contains the executable statements, and it typically ends with return 0;, signaling successful completion to the operating system. Understanding this skeleton is the first step in writing any C++ application, from simple console utilities to complex system software.

// Include necessary headers
#include <iostream>

// Use standard namespace
using namespace std;

// Main function - program entry point
int main() {
    // Your code here
    cout << "Welcome to C++!" << endl;
    
    // Return 0 for successful execution
    return 0;
}

Output:

Welcome to C++!

🔹 Variables and Data Types

Variables are named memory locations used to store and manipulate data, and their behavior is defined by their associated data type. Declaring a variable (e.g., int age;) allocates memory and specifies what kind of data it will hold. Initialization assigns an initial value at the point of declaration. The choice of data type (like char for a grade or int for an age) dictates the operations that can be performed and the memory used. Proper variable naming and type selection are cornerstones of writing clear, efficient, and maintainable code.

#include <iostream>
using namespace std;

int main() {
    // Integer
    int age = 25;
    
    // Floating point
    double price = 19.99;
    
    // Character
    char grade = 'A';
    
    // String
    string name = "John";
    
    // Boolean
    bool isStudent = true;
    
    cout << "Name: " << name << endl;
    cout << "Age: " << age << endl;
    cout << "Grade: " << grade << endl;
    
    return 0;
}

Output:

Name: John
Age: 25
Grade: A

🧠 Test Your Knowledge

What is the entry point of a C++ program?