C++ Syntax and Comments
Read a program as named objects and statements, with comments explaining the reason for a rule.
How it works
A declaration introduces a name and type. A statement performs an action or controls execution. Braces define a block, which can introduce local names whose scope ends at its closing brace. Use comments to explain a requirement rather than narrating every symbol. A delivery rule such as one spare label per round deserves a name and a short reason. Comments are not checked by the compiler, so keep them consistent with code and tests when the requirement changes.
Run it locally
Use a C++20 compiler and matching standard library in a separate lab folder. The command uses c++; substitute g++, clang++ or zig c++ for your toolchain. C++ does not currently run in Bhylu’s browser playground. Apache, PHP and MySQL are not needed.
c++ -std=c++20 -Wall -Wextra -Wpedantic -Werror program-shape.cpp -o lessonOn Windows use -o lesson.exe and run .\lesson.exe in PowerShell. On Unix-like systems run ./lesson. Thread examples may need -pthread on your platform.
Download the complete C++ source. Run file labs in a private empty directory, away from existing reports.
Example
#include <iostream>
int main() {
int labels{12};
{
// Keep one spare label for a damaged parcel label.
const int reserve{1};
labels -= reserve;
}
std::cout << "Usable labels: " << labels << '\n';
}
Expected result
Usable labels: 11
labels belongs to main, while reserve is visible only inside the nested block. The compound assignment changes the existing count. Case and spelling matter to identifiers. Indentation helps a human see structure, but braces and tokens determine the language meaning. Line and block comments are both available; block comments do not nest.
Consult the WG21 C++ working group and the C++ Core Guidelines for language references and design guidance. Check the selected standard version and your implementation’s library support.