Tutorials Logic, IN info@tutorialslogic.com
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Website Development
Practice
Quiz Challenge Interview Questions Certification Practice
Compiler Tools

What is C++? Introduction and Overview

What is C++?

C++ is a general-purpose, compiled, statically-typed programming language created by Bjarne Stroustrup in 1979 at Bell Labs as an extension of C. Originally called "C with Classes", it was renamed to C++ in 1983 — the ++ being C's increment operator, symbolising an improvement over C.

C++ combines low-level memory control with high-level abstractions (OOP, templates, STL). It powers operating systems, game engines, browsers, databases, and embedded systems — anywhere performance and control matter.

History of C++

YearMilestone
1979Bjarne Stroustrup begins "C with Classes" at Bell Labs
1983Renamed to C++; virtual functions and function overloading added
1985First commercial release; "The C++ Programming Language" book published
1998C++98 — first ISO standard; STL included
2011C++11 — major update: auto, lambda, smart pointers, move semantics, threads
2014C++14 — generic lambdas, make_unique
2017C++17 — structured bindings, std::optional, std::variant, filesystem
2020C++20 — concepts, ranges, coroutines, modules, std::format
2023C++23 — std::print, std::expected, flat_map

Features of C++

  • Object-Oriented Programming — classes, objects, inheritance, polymorphism, encapsulation, abstraction.
  • Generic Programming — templates let you write type-independent code; the entire STL is built on this.
  • Low-level Memory Control — direct pointer manipulation, new/delete, and smart pointers.
  • High Performance — compiled to native machine code; zero-cost abstractions mean you only pay for what you use.
  • Standard Template Library (STL) — ready-made containers (vector, map, set), algorithms (sort, find), and iterators.
  • Multi-paradigm — supports procedural, object-oriented, generic, and functional programming styles.
  • Portability — compiles on Windows, Linux, macOS, and embedded platforms.
  • RAII — Resource Acquisition Is Initialization: resources are tied to object lifetimes, preventing leaks automatically.
  • Exception Handling — structured error handling with try/catch/throw.
  • Operator Overloading — define custom behaviour for operators like +, -, ==, << on your own types.

C++ vs C — Key Differences

FeatureCC++
ParadigmProcedural onlyProcedural + OOP + Generic + Functional
Classes / ObjectsNoYes — core feature
InheritanceNoYes (single, multiple, virtual)
Function overloadingNoYes
Operator overloadingNoYes
TemplatesNoYes — generic programming
Exception handlingNo (use errno)Yes — try/catch/throw
Standard I/Oprintf / scanfcout / cin (streams)
String typechar array onlystd::string class
Memory managementmalloc / freenew / delete + smart pointers
NamespacesNoYes — prevents name collisions
ReferencesNoYes — safer alias for variables
bool typeNo (use int)Yes — native bool
File extension.c.cpp / .cxx / .cc

Structure of a C++ Program

Every C++ program follows a predictable structure. Understanding each part is essential before writing any code.

Anatomy of a C++ Program
// 1. Preprocessor directive — includes the iostream header
#include <iostream>

// 2. Using declaration — avoids writing std:: prefix everywhere
using namespace std;

// 3. main() — entry point of every C++ program
//    int return type: 0 = success, non-zero = error
int main() {

    // 4. cout — standard output stream
    //    <<  — stream insertion operator
    //    endl — newline + flush buffer (\n is faster)
    cout << "Hello, World!" << endl;

    // 5. Variables — must declare type before use
    int    age    = 25;
    double salary = 55000.50;
    string name   = "Alice";

    cout << name << " is " << age << " years old." << endl;

    // 6. return 0 — signals successful program termination
    return 0;
}

/*
 * Output:
 * Hello, World!
 * Alice is 25 years old.
 */
// A C++ program with a class — the OOP way
#include <iostream>
#include <string>
using namespace std;

// Class definition — blueprint for objects
class Car {
private:                    // only accessible inside the class
    string brand;
    int    year;

public:                     // accessible from outside
    // Constructor — called when object is created
    Car(string brand, int year) : brand(brand), year(year) {}

    // Member function (method)
    void display() const {
        cout << year << " " << brand << endl;
    }
};

int main() {
    Car c1("Toyota", 2022);   // create object on stack
    Car c2("BMW",    2024);

    c1.display();   // 2022 Toyota
    c2.display();   // 2024 BMW

    return 0;
}

C++ Compilation Model

Unlike interpreted languages (Python, JavaScript), C++ is compiled — source code is translated to machine code before running. The process has four stages:

StageToolInputOutputWhat happens
1. Preprocessingcpp.cpp.iExpands #include, #define, removes comments
2. Compilationg++/clang++.i.sTranslates C++ to assembly language
3. Assemblyas.s.oConverts assembly to object (machine) code
4. Linkingld.o + libsexecutableCombines object files and libraries into final program
Compile and Run Commands
# Compile
g++ hello.cpp -o hello

# Compile with C++17 standard and all warnings (recommended)
g++ -std=c++17 -Wall -Wextra hello.cpp -o hello

# Run on Linux/macOS
./hello

# Run on Windows
hello.exe

# See each compilation stage
g++ -E hello.cpp -o hello.i    # preprocessing only
g++ -S hello.cpp -o hello.s    # compile to assembly
g++ -c hello.cpp -o hello.o    # compile to object file
g++ hello.o -o hello           # link to executable

Applications of C++

DomainExamples
Operating SystemsWindows kernel, parts of Linux, macOS
Game EnginesUnreal Engine, CryEngine, id Tech
Web BrowsersGoogle Chrome (V8 engine), Mozilla Firefox
DatabasesMySQL, MongoDB, SQLite
Compilers / InterpretersGCC, Clang, Python interpreter (CPython)
Embedded SystemsArduino, automotive ECUs, IoT devices
Finance / TradingHigh-frequency trading systems, Bloomberg Terminal
Graphics / MultimediaAdobe Photoshop, Autodesk Maya, OpenCV
Machine LearningTensorFlow core, PyTorch C++ backend

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.