Edit the C++ example below and click Run to compile and execute it. The output panel shows stdout and any errors.
C++ Tutorial
Learn C++ Tutorial with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ HOME
Learn C++ HOME with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Intro
Learn C++ Intro with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Get Started
Learn C++ Get Started with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Syntax
Learn C++ Syntax with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Output
Learn C++ Output with a small example you can edit and run.
#include <iostream>
int main(){ std::cout << "Hi\n"; }
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Comments
Learn C++ Comments with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#include <iostream> | Includes a standard header. |
int main() { | Program entry point. |
/* multi-line | C++ statement line. |
comment */ | C++ statement line. |
std::cout << "Comments do not change output" << "\n"; | Prints output. |
return 0; | C++ statement line. |
} | C++ statement line. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Variables
Learn C++ Variables with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ User Input
Learn C++ User Input with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 Types
Learn C++ Data Types with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Operators
Learn C++ Operators with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Strings
Learn C++ Strings with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Math
Learn C++ Math with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Booleans
Learn C++ Booleans with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ If...Else
Learn C++ If...Else with a small example you can edit and run.
if (condition) {
// ...
} else {
// ...
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Switch
Learn C++ Switch with a small example you can edit and run.
switch (value) {
case 1: break;
default: break;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ While Loop
Learn C++ While Loop with a small example you can edit and run.
while (condition) {
// ...
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ For Loop
Learn C++ For Loop with a small example you can edit and run.
for (int i = 0; i < n; i++) {
// ...
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Break/Continue
Learn C++ Break/Continue with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Arrays
Learn C++ Arrays with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Structures
Learn C++ Structures with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Enums
Learn C++ Enums with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ References
Learn C++ References with a small example you can edit and run.
int x = 5;
int& r = x;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Pointers
Learn C++ Pointers with a small example you can edit and run.
int x = 5;
int* p = &x;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Manual memory management appears in legacy code and low-level systems.
- 2Smart pointers and RAII are the modern default.
- 1Dangling pointers and double delete.
- 2Forgetting to free resources.
- 1Prefer RAII and standard containers.
- 2Use smart pointers when owning heap memory.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Memory Management
Learn C++ Memory Management with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Manual memory management appears in legacy code and low-level systems.
- 2Smart pointers and RAII are the modern default.
- 1Dangling pointers and double delete.
- 2Forgetting to free resources.
- 1Prefer RAII and standard containers.
- 2Use smart pointers when owning heap memory.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Functions with a small example you can edit and run.
return_type name(type arg) {
return value;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 (Functions)
Learn C++ Functions (Functions) with a small example you can edit and run.
return_type name(type arg) {
return value;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Function Parameters
Learn C++ Function Parameters with a small example you can edit and run.
return_type name(type arg) {
return value;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Function Overloading
Learn C++ Function Overloading with a small example you can edit and run.
return_type name(type arg) {
return value;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Scope
Learn C++ Scope with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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 x | Assigns 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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Recursion
Learn C++ Recursion with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Lambda
Learn C++ Lambda with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Classes with a small example you can edit and run.
class Name {
public:
Name();
void method();
};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ OOP
Learn C++ OOP with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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/Objects
Learn C++ Classes/Objects with a small example you can edit and run.
class Name {
public:
Name();
void method();
};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Class Methods
Learn C++ Class Methods with a small example you can edit and run.
class Name {
public:
Name();
void method();
};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Constructors
Learn C++ Constructors with a small example you can edit and run.
class Name {
public:
Name();
void method();
};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Access Specifiers
Learn C++ Access Specifiers with a small example you can edit and run.
if (condition) {
// ...
} else {
// ...
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Encapsulation
Learn C++ Encapsulation with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Friend Functions
Learn C++ Friend Functions with a small example you can edit and run.
return_type name(type arg) {
return value;
}
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Inheritance
Learn C++ Inheritance with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Polymorphism
Learn C++ Polymorphism with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Templates
Learn C++ Templates with a small example you can edit and run.
template <typename T>
T add(T a, T b) { return a + b; }
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Files
Learn C++ Files with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Date
Learn C++ Date with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Errors with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Handle invalid inputs and parsing failures safely.
- 2Turn failures into clear user-facing messages.
- 1Ignoring error paths.
- 2Catching exceptions by value (copy).
- 1Catch exceptions by `const std::exception&`.
- 2Validate inputs early.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 (Errors)
Learn C++ Errors (Errors) with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Handle invalid inputs and parsing failures safely.
- 2Turn failures into clear user-facing messages.
- 1Ignoring error paths.
- 2Catching exceptions by value (copy).
- 1Catch exceptions by `const std::exception&`.
- 2Validate inputs early.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Debugging
Learn C++ Debugging with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Exceptions
Learn C++ Exceptions with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Handle invalid inputs and parsing failures safely.
- 2Turn failures into clear user-facing messages.
- 1Ignoring error paths.
- 2Catching exceptions by value (copy).
- 1Catch exceptions by `const std::exception&`.
- 2Validate inputs early.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Input Validation
Learn C++ Input Validation with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1Handle invalid inputs and parsing failures safely.
- 2Turn failures into clear user-facing messages.
- 1Ignoring error paths.
- 2Catching exceptions by value (copy).
- 1Catch exceptions by `const std::exception&`.
- 2Validate inputs early.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Data Structures with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 & STL
Learn C++ Data Structures & STL with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Vectors
Learn C++ Vectors with a small example you can edit and run.
#include <vector>
std::vector<int> v = {1,2,3};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ List
Learn C++ List with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Stacks
Learn C++ Stacks with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Queues
Learn C++ Queues with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Deque
Learn C++ Deque with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Sets
Learn C++ Sets with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Maps
Learn C++ Maps with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Iterators
Learn C++ Iterators with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Algorithms
Learn C++ Algorithms with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Namespaces with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 (Namespaces)
Learn C++ Namespaces (Namespaces) with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Projects with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 (Projects)
Learn C++ Projects (Projects) with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ How To with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Add Two Numbers
Learn C++ Add Two Numbers with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Random Numbers
Learn C++ Random Numbers with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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
Learn C++ Reference with a small example you can edit and run.
int x = 5;
int& r = x;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 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 (Reference)
Learn C++ Reference (Reference) with a small example you can edit and run.
int x = 5;
int& r = x;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ Keywords
Learn C++ Keywords with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <iostream>
Learn C++ <iostream> with a small example you can edit and run.
#include <iostream>
int main(){ std::cout << "Hi\n"; }
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <fstream>
Learn C++ <fstream> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <cmath>
Learn C++ <cmath> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <string>
Learn C++ <string> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <cstring>
Learn C++ <cstring> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <ctime>
Learn C++ <ctime> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1C++ is used in performance-sensitive systems, games, and embedded software.
- 1Forgetting headers or missing semicolons.
- 1Compile often and fix errors one-by-one.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <vector>
Learn C++ <vector> with a small example you can edit and run.
#include <vector>
std::vector<int> v = {1,2,3};
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.
C++ <algorithm>
Learn C++ <algorithm> with a small example you can edit and run.
statement;
Edit the C++ code below and click Run. The output panel shows stdout and compile/runtime errors.
| Line | Meaning |
|---|---|
#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. |
- 1STL is the daily toolkit: vectors, maps, sets, algorithms.
- 2Write less code by using library utilities.
- 1Off-by-one iterator mistakes.
- 2Copying large containers unnecessarily.
- 1Prefer range-based for loops.
- 2Pass by const reference when appropriate.
- 1Practice the pattern in a tiny program, then reuse it in a project.
- 2Prefer readable code and safe defaults (RAII, STL).
- 1Change one line and predict the output before running.
- 2Add one edge case and handle it safely.
- 3Explain the result in 1 sentence.