Define and call a function
#The return type comes first, followed by the name and typed parameters. void declares no returned value.
Fragment
Function declaration, then a call fragment inside main.
Reference
Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
C++ docs Functions ↗Lambda expressions ↗
The return type comes first, followed by the name and typed parameters. void declares no returned value.
Fragment
Function declaration, then a call fragment inside main.
A hosted executable starts at main. Returning 0 signals success; reaching the end of main also returns 0.
Fragment
Complete main.cpp.
class members are private by default; public: exposes members. struct defaults to public. Methods access instance fields. LinePrinter, push and finish are exercise-defined.
Fragment
Class declaration at file scope; value statements inside a function.
A constructor has the class name and no return type. The : value(start) member initializer initializes the field before the body runs. explicit prevents implicit conversions through this constructor. Token item{24} creates an automatic object without a new expression.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
[] introduces a lambda; its capture list chooses how outside locals are retained. [factor] copies factor; [&factor] borrows it and requires a valid lifetime. mutable permits changes to captured copies.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Default arguments fill omitted trailing arguments; overloads are another facility. Variadic templates accept parameter packs. A C-style ... function has different type-safety rules and is not equivalent to a rest array.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.