🛡 C++ — Learn From Zero

Playground: Replit C++ | JDoodle — click, type, run.

What is C++?

C++ adds classes, templates, and STL on top of C. It's used where speed and control matter: games, finance, robotics.

  • Game engines (Unreal)
  • High-frequency trading
  • Operating systems & browsers
  • Embedded systems

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

cpp
#include 
int main() {
  std::cout << "Hello, world!" << std::endl;
  return 0;
}

Use std::cout for output.

Variables & Types

cpp
int age = 36;
double height = 1.78;
bool isStudent = true;
std::string name = "Ada";

C++ adds std::string and bool.

If / Else

cpp
int age = 18;
if (age >= 18) std::cout << "Vote\n";
else std::cout << "Too young\n";

Same control flow as C.

Loops

cpp
for (int i = 0; i < 5; i++) std::cout << i << "\n";

Range-based: for (auto x : vec).

Functions

cpp
int add(int a, int b) {
  return a + b;
}

Overloading allowed by signature.

Classes

cpp
class Person {
public:
  std::string name;
  int age;
};

Encapsulate with public/private.

🟡 Intermediate — Building Real Programs

STL Containers

cpp
#include 
std::vector v = {1, 2, 3};
v.push_back(4);

Use vector, map, set.

Templates

cpp
template
T max(T a, T b) { return a > b ? a : b; }

Build generic code.

References

cpp
int x = 5;
int &r = x;
r = 10;
// x is now 10

References are aliases, safer than pointers.

RAII

cpp
{
  std::vector v(1000);
} // automatically freed

Resources freed by destructors.

Inheritance

cpp
class Animal { public: virtual void speak() = 0; };
class Dog : public Animal { void speak() override {} };

Polymorphism via virtual methods.

🔴 Advanced — Pro Concepts

Lambdas

cpp
auto sum = [](int a, int b) { return a + b; };
std::cout << sum(2, 3);

Inline anonymous functions.

Smart Pointers

cpp
#include 
auto p = std::make_unique(5);

Automatic memory management.

Move Semantics

cpp
std::vector a = {1,2,3};
std::vector b = std::move(a);

Avoid costly copies.

Concurrency

cpp
#include 
std::thread t([](){ /* work */ });
t.join();

Spawn threads with std::thread.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.