ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

C++ Tutorial• 6 min read

C++ Introduction & From C to Modern C++

Namespaces, std::cout, references, and auto type deduction

Created in 1979 by Bjarne Stroustrup as "C with Classes", Modern C++ (C++11 through C++23) is a multi-paradigm language offering zero-cost abstractions, deterministic destructors, and extreme performance.

Modern C++ Foundations

std::cout & Streams: Stream insertion operator << replaces unsafe printf format strings with type-safe stream output.

Namespaces: namespace my_ns { ... } avoids global naming collisions. Access members using the scope resolution operator ::.

auto: The compiler automatically deduces variable types at compile-time with zero runtime performance cost.

Modern C++ Hello World
#include <iostream>
#include <string>

int main() {
    // auto automatically deduces std::string
    auto message = "Welcome to Modern C++!";
    int xp = 150;

    std::cout << message << " | Learner XP: " << xp << std::endl;
    return 0;
}
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

What is the purpose of the `auto` keyword in Modern C++ (C++11 and later)?