Declare, infer, reassign
#Types precede names. auto deduces a type; it does not imply const. const prevents modification through this object.
Fragment
Fragment inside a function.
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 Initialization ↗Declarations ↗
Types precede names. auto deduces a type; it does not imply const. const prevents modification through this object.
Fragment
Fragment inside a function.
A declaration in a nested block can hide an outer local name. Assignment uses the name visible at that point. Leaving the nested block makes the outer binding visible again; an ordinary local cannot be redeclared in the same scope.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Local scalar declarations without initialization can leave unusable values. Empty braces value-initialize simple scalar objects; class initialization follows its constructors/member defaults. Prefer explicit initialization.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Standard containers and strings compare contents. Raw pointers compare addresses, including pointers to string literals. A custom record can define or default operator== (defaulted comparison is C++20).
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Copying vector/string values normally duplicates their owned elements. Copying pointers or shared_ptr shares access/ownership instead. std::move permits move overload selection; it is a cast and does not itself transfer storage.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.