Fast. Powerful. System Level.

C++ — Complete Tutorial

Learn C++ from absolute zero. Every topic explained simply with real examples you can edit and understand quickly.

🟩 Beginner Friendly ▶ Live Code Editor 📚 79 Topics
Your Progress3% complete
Live C++ Lab

Edit the C++ example below and click Run to compile and execute it. The output panel shows stdout and any errors.

cpp-lab.cpp
📝 Edit Code
👁 Output
💡 Try this: modify values and method logic, then run again.
∙ Chapter 001

C++ Tutorial

Learn C++ Tutorial with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-tutorial.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Welcome to C++" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 002

C++ HOME

Learn C++ HOME with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-home.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Welcome to C++" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 003

C++ Intro

Learn C++ Intro with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-intro.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Welcome to C++" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 004

C++ Get Started

Learn C++ Get Started with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-get-started.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Welcome to C++" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 005

C++ Syntax

Learn C++ Syntax with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-syntax.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Hello" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 006

C++ Output

Learn C++ Output with a small example you can edit and run.

📝Syntax
#include <iostream>
int main(){ std::cout << "Hi\n"; }
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-output.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Hello" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 007

C++ Comments

Learn C++ Comments with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-comments.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
/* multi-lineC++ statement line.
comment */C++ statement line.
std::cout << "Comments do not change output" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 008

C++ Variables

Learn C++ Variables with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-variables.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string name = "Mana";Assigns a value.
int level = 1;Assigns a value.
level++;C++ statement line.
std::cout << name << " level " << level << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 009

C++ User Input

Learn C++ User Input with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-user-input.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string name;C++ statement line.
std::cout << "Enter name: ";Prints output.
std::cin >> name;Reads user input.
std::cout << "Hello, " << name << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 010

C++ Data Types

Learn C++ Data Types with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-data-types.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int a = 7;Assigns a value.
double b = 3.14;Assigns a value.
bool ok = true;Assigns a value.
std::cout << a << " " << b << " " << ok << "\n";Prints output.
std::cout << "sizeof(int)=" << sizeof(int) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 011

C++ Operators

Learn C++ Operators with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-operators.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int a = 7, b = 3;Assigns a value.
std::cout << "a+b=" << (a + b) << "\n";Prints output.
std::cout << "a>b=" << (a > b) << "\n";Prints output.
std::cout << "a% b=" << (a % b) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 012

C++ Strings

Learn C++ Strings with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-strings.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "manacoding";Assigns a value.
std::cout << "len=" << s.size() << "\n";Prints output.
std::cout << s.substr(0, 4) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 013

C++ Math

Learn C++ Math with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-math.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <cmath>Includes a standard header.
int main() {Program entry point.
std::cout << std::sqrt(81.0) << "\n";Prints output.
std::cout << std::pow(2.0, 10.0) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 014

C++ Booleans

Learn C++ Booleans with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-booleans.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int score = 72;Assigns a value.
if (score >= 75) {Conditional branch.
std::cout << "Pass\n";Prints output.
} else {C++ statement line.
std::cout << "Try again\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 015

C++ If...Else

Learn C++ If...Else with a small example you can edit and run.

📝Syntax
if (condition) {
  // ...
} else {
  // ...
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-if-else.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int score = 72;Assigns a value.
if (score >= 75) {Conditional branch.
std::cout << "Pass\n";Prints output.
} else {C++ statement line.
std::cout << "Try again\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 016

C++ Switch

Learn C++ Switch with a small example you can edit and run.

📝Syntax
switch (value) {
  case 1: break;
  default: break;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-switch.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int day = 3;Assigns a value.
switch (day) {Control flow statement.
case 1: std::cout << "Mon\n"; break;Control flow statement.
case 2: std::cout << "Tue\n"; break;Control flow statement.
case 3: std::cout << "Wed\n"; break;Control flow statement.
default: std::cout << "Other\n"; break;Control flow statement.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 017

C++ While Loop

Learn C++ While Loop with a small example you can edit and run.

📝Syntax
while (condition) {
  // ...
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-while-loop.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int n = 1;Assigns a value.
int sum = 0;Assigns a value.
while (n <= 5) {Control flow statement.
sum += n;Assigns a value.
n++;C++ statement line.
}C++ statement line.
std::cout << sum << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 018

C++ For Loop

Learn C++ For Loop with a small example you can edit and run.

📝Syntax
for (int i = 0; i < n; i++) {
  // ...
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-for-loop.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
for (int i = 1; i <= 3; i++) {Control flow statement.
std::cout << "i=" << i << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 019

C++ Break/Continue

Learn C++ Break/Continue with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-break-continue.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
for (int i = 1; i <= 6; i++) {Control flow statement.
if (i == 3) continue;Conditional branch.
if (i == 5) break;Conditional branch.
std::cout << i << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 020

C++ Arrays

Learn C++ Arrays with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-arrays.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int nums[4] = {1, 2, 3, 4};Assigns a value.
int sum = 0;Assigns a value.
for (int x : nums) sum += x;Control flow statement.
std::cout << sum << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 021

C++ Structures

Learn C++ Structures with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-structures.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
struct User {Defines a struct (public by default).
std::string name;C++ statement line.
int level;C++ statement line.
};C++ statement line.
int main() {Program entry point.
User u{"Mana", 2};C++ statement line.
std::cout << u.name << " " << u.level << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 022

C++ Enums

Learn C++ Enums with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-enums.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
enum class Role { User, Admin };Defines an enum type.
int main() {Program entry point.
Role r = Role::Admin;Assigns a value.
std::cout << (r == Role::Admin) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 023

C++ References

Learn C++ References with a small example you can edit and run.

📝Syntax
int x = 5;
int& r = x;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-references.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int x = 10;Assigns a value.
int& r = x;Assigns a value.
r += 5;Assigns a value.
std::cout << x << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 024

C++ Pointers

Learn C++ Pointers with a small example you can edit and run.

📝Syntax
int x = 5;
int* p = &x;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-pointers.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int x = 10;Assigns a value.
int* p = &x;Assigns a value.
*p += 2;Assigns a value.
std::cout << x << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Manual memory management appears in legacy code and low-level systems.
  • 2Smart pointers and RAII are the modern default.
Common Mistakes
  • 1Dangling pointers and double delete.
  • 2Forgetting to free resources.
Best Practices
  • 1Prefer RAII and standard containers.
  • 2Use smart pointers when owning heap memory.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 025

C++ Memory Management

Learn C++ Memory Management with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-memory-management.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int* p = new int(42);Assigns a value.
std::cout << *p << "\n";Prints output.
delete p;C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Manual memory management appears in legacy code and low-level systems.
  • 2Smart pointers and RAII are the modern default.
Common Mistakes
  • 1Dangling pointers and double delete.
  • 2Forgetting to free resources.
Best Practices
  • 1Prefer RAII and standard containers.
  • 2Use smart pointers when owning heap memory.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Functions
∙ Chapter 026

C++ Functions

Learn C++ Functions with a small example you can edit and run.

📝Syntax
return_type name(type arg) {
  return value;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-functions.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
std::string greet(const std::string& name) {C++ statement line.
return "Hello, " + name;C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << greet("Developer") << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 027

C++ Functions (Functions)

Learn C++ Functions (Functions) with a small example you can edit and run.

📝Syntax
return_type name(type arg) {
  return value;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-functions.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
std::string greet(const std::string& name) {C++ statement line.
return "Hello, " + name;C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << greet("Developer") << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 028

C++ Function Parameters

Learn C++ Function Parameters with a small example you can edit and run.

📝Syntax
return_type name(type arg) {
  return value;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-function-parameters.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
std::string greet(const std::string& name) {C++ statement line.
return "Hello, " + name;C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << greet("Developer") << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 029

C++ Function Overloading

Learn C++ Function Overloading with a small example you can edit and run.

📝Syntax
return_type name(type arg) {
  return value;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-function-overloading.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int add(int a, int b) { return a + b; }C++ statement line.
double add(double a, double b) { return a + b; }C++ statement line.
int main() {Program entry point.
std::cout << add(7, 5) << "\n";Prints output.
std::cout << add(0.1, 0.2) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 030

C++ Scope

Learn C++ Scope with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-scope.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int x = 1;Assigns a value.
{C++ statement line.
int x = 2; // shadows outer xAssigns a value.
std::cout << x << "\n";Prints output.
}C++ statement line.
std::cout << x << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 031

C++ Recursion

Learn C++ Recursion with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-recursion.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int fact(int n) {C++ statement line.
if (n <= 1) return 1;Conditional branch.
return n * fact(n - 1);C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << fact(5) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 032

C++ Lambda

Learn C++ Lambda with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-lambda.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
auto add = [](int a, int b) { return a + b; };Assigns a value.
std::cout << add(7, 5) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Classes & OOP
∙ Chapter 033

C++ Classes

Learn C++ Classes with a small example you can edit and run.

📝Syntax
class Name {
public:
  Name();
  void method();
};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-classes.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
class User {Defines a class.
std::string name;C++ statement line.
public:C++ statement line.
User(std::string n) : name(std::move(n)) {}C++ statement line.
void greet() const { std::cout << "Hi, " << name << "\n"; }Prints output.
};C++ statement line.
int main() {Program entry point.
User u("Mana");C++ statement line.
u.greet();C++ statement line.
return 0;C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 034

C++ OOP

Learn C++ OOP with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-oop.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 035

C++ Classes/Objects

Learn C++ Classes/Objects with a small example you can edit and run.

📝Syntax
class Name {
public:
  Name();
  void method();
};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-classes-objects.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
class User {Defines a class.
std::string name;C++ statement line.
public:C++ statement line.
User(std::string n) : name(std::move(n)) {}C++ statement line.
void greet() const { std::cout << "Hi, " << name << "\n"; }Prints output.
};C++ statement line.
int main() {Program entry point.
User u("Mana");C++ statement line.
u.greet();C++ statement line.
return 0;C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 036

C++ Class Methods

Learn C++ Class Methods with a small example you can edit and run.

📝Syntax
class Name {
public:
  Name();
  void method();
};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-class-methods.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
class User {Defines a class.
std::string name;C++ statement line.
public:C++ statement line.
User(std::string n) : name(std::move(n)) {}C++ statement line.
void greet() const { std::cout << "Hi, " << name << "\n"; }Prints output.
};C++ statement line.
int main() {Program entry point.
User u("Mana");C++ statement line.
u.greet();C++ statement line.
return 0;C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 037

C++ Constructors

Learn C++ Constructors with a small example you can edit and run.

📝Syntax
class Name {
public:
  Name();
  void method();
};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-constructors.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
struct User {Defines a struct (public by default).
std::string name;C++ statement line.
int level;C++ statement line.
};C++ statement line.
int main() {Program entry point.
User u{"Mana", 2};C++ statement line.
std::cout << u.name << " " << u.level << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 038

C++ Access Specifiers

Learn C++ Access Specifiers with a small example you can edit and run.

📝Syntax
if (condition) {
  // ...
} else {
  // ...
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-access-specifiers.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int score = 72;Assigns a value.
if (score >= 75) {Conditional branch.
std::cout << "Pass\n";Prints output.
} else {C++ statement line.
std::cout << "Try again\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 039

C++ Encapsulation

Learn C++ Encapsulation with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-encapsulation.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 040

C++ Friend Functions

Learn C++ Friend Functions with a small example you can edit and run.

📝Syntax
return_type name(type arg) {
  return value;
}
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-friend-functions.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
std::string greet(const std::string& name) {C++ statement line.
return "Hello, " + name;C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << greet("Developer") << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 041

C++ Inheritance

Learn C++ Inheritance with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-inheritance.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
struct Base {Defines a struct (public by default).
virtual ~Base() = default;Assigns a value.
virtual void speak() const { std::cout << "Base\n"; }Prints output.
};C++ statement line.
struct Derived : Base {Defines a struct (public by default).
void speak() const override { std::cout << "Derived\n"; }Prints output.
};C++ statement line.
int main() {Program entry point.
Base* b = new Derived();Assigns a value.
b->speak();C++ statement line.
delete b;C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 042

C++ Polymorphism

Learn C++ Polymorphism with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-polymorphism.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
struct Base {Defines a struct (public by default).
virtual ~Base() = default;Assigns a value.
virtual void speak() const { std::cout << "Base\n"; }Prints output.
};C++ statement line.
struct Derived : Base {Defines a struct (public by default).
void speak() const override { std::cout << "Derived\n"; }Prints output.
};C++ statement line.
int main() {Program entry point.
Base* b = new Derived();Assigns a value.
b->speak();C++ statement line.
delete b;C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 043

C++ Templates

Learn C++ Templates with a small example you can edit and run.

📝Syntax
template <typename T>
T add(T a, T b) { return a + b; }
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-templates.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
template <typename T>Declares a template.
T add(T a, T b) { return a + b; }C++ statement line.
int main() {Program entry point.
std::cout << add<int>(7, 5) << "\n";Prints output.
std::cout << add<double>(0.1, 0.2) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 044

C++ Files

Learn C++ Files with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-files.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <fstream>Includes a standard header.
int main() {Program entry point.
std::cout << "File I/O uses <fstream> (read/write files)" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 045

C++ Date

Learn C++ Date with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-date.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <ctime>Includes a standard header.
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::time_t t = std::time(nullptr);Assigns a value.
std::cout << std::ctime(&t);Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Errors
∙ Chapter 046

C++ Errors

Learn C++ Errors with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-errors.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "123";Assigns a value.
try {Exception handling.
int n = std::stoi(s);Assigns a value.
std::cout << (n + 7) << "\n";Prints output.
} catch (const std::exception& e) {C++ statement line.
std::cout << "Error: " << e.what() << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Handle invalid inputs and parsing failures safely.
  • 2Turn failures into clear user-facing messages.
Common Mistakes
  • 1Ignoring error paths.
  • 2Catching exceptions by value (copy).
Best Practices
  • 1Catch exceptions by `const std::exception&`.
  • 2Validate inputs early.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 047

C++ Errors (Errors)

Learn C++ Errors (Errors) with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-errors.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "123";Assigns a value.
try {Exception handling.
int n = std::stoi(s);Assigns a value.
std::cout << (n + 7) << "\n";Prints output.
} catch (const std::exception& e) {C++ statement line.
std::cout << "Error: " << e.what() << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Handle invalid inputs and parsing failures safely.
  • 2Turn failures into clear user-facing messages.
Common Mistakes
  • 1Ignoring error paths.
  • 2Catching exceptions by value (copy).
Best Practices
  • 1Catch exceptions by `const std::exception&`.
  • 2Validate inputs early.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 048

C++ Debugging

Learn C++ Debugging with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-debugging.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 049

C++ Exceptions

Learn C++ Exceptions with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-exceptions.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "123";Assigns a value.
try {Exception handling.
int n = std::stoi(s);Assigns a value.
std::cout << (n + 7) << "\n";Prints output.
} catch (const std::exception& e) {C++ statement line.
std::cout << "Error: " << e.what() << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Handle invalid inputs and parsing failures safely.
  • 2Turn failures into clear user-facing messages.
Common Mistakes
  • 1Ignoring error paths.
  • 2Catching exceptions by value (copy).
Best Practices
  • 1Catch exceptions by `const std::exception&`.
  • 2Validate inputs early.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 050

C++ Input Validation

Learn C++ Input Validation with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-input-validation.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "123";Assigns a value.
try {Exception handling.
int n = std::stoi(s);Assigns a value.
std::cout << (n + 7) << "\n";Prints output.
} catch (const std::exception& e) {C++ statement line.
std::cout << "Error: " << e.what() << "\n";Prints output.
}C++ statement line.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1Handle invalid inputs and parsing failures safely.
  • 2Turn failures into clear user-facing messages.
Common Mistakes
  • 1Ignoring error paths.
  • 2Catching exceptions by value (copy).
Best Practices
  • 1Catch exceptions by `const std::exception&`.
  • 2Validate inputs early.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Data Structures
∙ Chapter 051

C++ Data Structures

Learn C++ Data Structures with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-data-structures.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
struct User {Defines a struct (public by default).
std::string name;C++ statement line.
int level;C++ statement line.
};C++ statement line.
int main() {Program entry point.
User u{"Mana", 2};C++ statement line.
std::cout << u.name << " " << u.level << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 052

C++ Data Structures & STL

Learn C++ Data Structures & STL with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-data-structures-and-stl.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
struct User {Defines a struct (public by default).
std::string name;C++ statement line.
int level;C++ statement line.
};C++ statement line.
int main() {Program entry point.
User u{"Mana", 2};C++ statement line.
std::cout << u.name << " " << u.level << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 053

C++ Vectors

Learn C++ Vectors with a small example you can edit and run.

📝Syntax
#include <vector>
std::vector<int> v = {1,2,3};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-vectors.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <vector>Includes a standard header.
int main() {Program entry point.
std::vector<int> v = {3, 1, 2};Assigns a value.
int sum = 0;Assigns a value.
for (int x : v) sum += x;Control flow statement.
std::cout << sum << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 054

C++ List

Learn C++ List with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-list.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <deque>Includes a standard header.
int main() {Program entry point.
std::deque<int> d;C++ statement line.
d.push_back(1);C++ statement line.
d.push_front(0);C++ statement line.
std::cout << d.front() << " " << d.back() << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 055

C++ Stacks

Learn C++ Stacks with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-stacks.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <deque>Includes a standard header.
int main() {Program entry point.
std::deque<int> d;C++ statement line.
d.push_back(1);C++ statement line.
d.push_front(0);C++ statement line.
std::cout << d.front() << " " << d.back() << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 056

C++ Queues

Learn C++ Queues with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-queues.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <deque>Includes a standard header.
int main() {Program entry point.
std::deque<int> d;C++ statement line.
d.push_back(1);C++ statement line.
d.push_front(0);C++ statement line.
std::cout << d.front() << " " << d.back() << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 057

C++ Deque

Learn C++ Deque with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-deque.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <deque>Includes a standard header.
int main() {Program entry point.
std::deque<int> d;C++ statement line.
d.push_back(1);C++ statement line.
d.push_front(0);C++ statement line.
std::cout << d.front() << " " << d.back() << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 058

C++ Sets

Learn C++ Sets with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-sets.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <set>Includes a standard header.
int main() {Program entry point.
std::set<int> s = {2, 1, 2, 3};Assigns a value.
std::cout << s.size() << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 059

C++ Maps

Learn C++ Maps with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-maps.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <map>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::map<std::string, int> m;C++ statement line.
m["mana"] = 2;Assigns a value.
m["mana"]++;C++ statement line.
std::cout << m["mana"] << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 060

C++ Iterators

Learn C++ Iterators with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-iterators.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 061

C++ Algorithms

Learn C++ Algorithms with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-algorithms.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <algorithm>Includes a standard header.
#include <iostream>Includes a standard header.
#include <vector>Includes a standard header.
int main() {Program entry point.
std::vector<int> v = {3, 1, 2};Assigns a value.
std::sort(v.begin(), v.end());C++ statement line.
for (int x : v) std::cout << x << " ";Control flow statement.
std::cout << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Namespaces
∙ Chapter 062

C++ Namespaces

Learn C++ Namespaces with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-namespaces.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
namespace app {C++ statement line.
int add(int a, int b) { return a + b; }C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << app::add(7, 5) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 063

C++ Namespaces (Namespaces)

Learn C++ Namespaces (Namespaces) with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-namespaces.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
namespace app {C++ statement line.
int add(int a, int b) { return a + b; }C++ statement line.
}C++ statement line.
int main() {Program entry point.
std::cout << app::add(7, 5) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Projects
∙ Chapter 064

C++ Projects

Learn C++ Projects with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-projects.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 065

C++ Projects (Projects)

Learn C++ Projects (Projects) with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-projects.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ How To
∙ Chapter 066

C++ How To

Learn C++ How To with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-how-to.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Practice: edit this example" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 067

C++ Add Two Numbers

Learn C++ Add Two Numbers with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-add-two-numbers.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int a = 7, b = 5;Assigns a value.
std::cout << (a + b) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 068

C++ Random Numbers

Learn C++ Random Numbers with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-random-numbers.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <random>Includes a standard header.
int main() {Program entry point.
std::mt19937 rng(42);C++ statement line.
std::uniform_int_distribution<int> dist(1, 6);C++ statement line.
std::cout << dist(rng) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
C++ Reference
∙ Chapter 069

C++ Reference

Learn C++ Reference with a small example you can edit and run.

📝Syntax
int x = 5;
int& r = x;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-reference.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int x = 10;Assigns a value.
int& r = x;Assigns a value.
r += 5;Assigns a value.
std::cout << x << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 070

C++ Reference (Reference)

Learn C++ Reference (Reference) with a small example you can edit and run.

📝Syntax
int x = 5;
int& r = x;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-reference.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
int x = 10;Assigns a value.
int& r = x;Assigns a value.
r += 5;Assigns a value.
std::cout << x << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 071

C++ Keywords

Learn C++ Keywords with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-keywords.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Use this section as a quick reference" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 072

C++ <iostream>

Learn C++ <iostream> with a small example you can edit and run.

📝Syntax
#include <iostream>
int main(){ std::cout << "Hi\n"; }
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-iostream.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::cout << "Hello" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 073

C++ <fstream>

Learn C++ <fstream> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-fstream.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <fstream>Includes a standard header.
int main() {Program entry point.
std::cout << "File I/O uses <fstream> (read/write files)" << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 074

C++ <cmath>

Learn C++ <cmath> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-cmath.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <cmath>Includes a standard header.
int main() {Program entry point.
std::cout << std::sqrt(81.0) << "\n";Prints output.
std::cout << std::pow(2.0, 10.0) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 075

C++ <string>

Learn C++ <string> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-string.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <string>Includes a standard header.
int main() {Program entry point.
std::string s = "manacoding";Assigns a value.
std::cout << "len=" << s.size() << "\n";Prints output.
std::cout << s.substr(0, 4) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 076

C++ <cstring>

Learn C++ <cstring> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-cstring.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <cstring>Includes a standard header.
#include <iostream>Includes a standard header.
int main() {Program entry point.
const char* a = "hi";Assigns a value.
std::cout << std::strlen(a) << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 077

C++ <ctime>

Learn C++ <ctime> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-ctime.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <ctime>Includes a standard header.
#include <iostream>Includes a standard header.
int main() {Program entry point.
std::time_t t = std::time(nullptr);Assigns a value.
std::cout << std::ctime(&t);Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1C++ is used in performance-sensitive systems, games, and embedded software.
Common Mistakes
  • 1Forgetting headers or missing semicolons.
Best Practices
  • 1Compile often and fix errors one-by-one.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 078

C++ <vector>

Learn C++ <vector> with a small example you can edit and run.

📝Syntax
#include <vector>
std::vector<int> v = {1,2,3};
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-vector.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <iostream>Includes a standard header.
#include <vector>Includes a standard header.
int main() {Program entry point.
std::vector<int> v = {3, 1, 2};Assigns a value.
int sum = 0;Assigns a value.
for (int x : v) sum += x;Control flow statement.
std::cout << sum << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
∙ Chapter 079

C++ <algorithm>

Learn C++ <algorithm> with a small example you can edit and run.

📝Syntax
statement;
Example (Edit & Run)

Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.

cpp-algorithm.cpp
📝 Edit Code
👁 Output
💡 Tip: if you get an error, read the first error line—fix that first.
🔍Line-by-line
LineMeaning
#include <algorithm>Includes a standard header.
#include <iostream>Includes a standard header.
#include <vector>Includes a standard header.
int main() {Program entry point.
std::vector<int> v = {3, 1, 2};Assigns a value.
std::sort(v.begin(), v.end());C++ statement line.
for (int x : v) std::cout << x << " ";Control flow statement.
std::cout << "\n";Prints output.
return 0;C++ statement line.
}C++ statement line.
🏢Real-world
  • 1STL is the daily toolkit: vectors, maps, sets, algorithms.
  • 2Write less code by using library utilities.
Common Mistakes
  • 1Off-by-one iterator mistakes.
  • 2Copying large containers unnecessarily.
Best Practices
  • 1Prefer range-based for loops.
  • 2Pass by const reference when appropriate.
📖Summary & Practice
  • 1Practice the pattern in a tiny program, then reuse it in a project.
  • 2Prefer readable code and safe defaults (RAII, STL).
💡Practice: answer the questions below, then modify the example to match your answers.
  • 1Change one line and predict the output before running.
  • 2Add one edge case and handle it safely.
  • 3Explain the result in 1 sentence.
PreviousBack to Home
🎉 C++ Tutorial Complete (79 topics)! You’re on the C++ page