var
The var keyword is used to declare mutable variables. Variables in Bjarne language are immutable by default; the var keyword opts into mutability.
Syntax
var Type Identifier = value;
var Type Identifier{};
Example Code
int32 immutable_value = 7; // cannot be reassigned
var int32 mutable_value = 7; // can be reassigned
mutable_value = 42;
Pointer Mutability
The var keyword can be applied independently to pointers and pointees:
Type* p // immutable pointer to immutable data
var Type* p // immutable pointer to mutable data
Type* var p // mutable pointer to immutable data
var Type* var p // mutable pointer to mutable data
Example Code
int32 value = 10;
var int32 mutable_value = 20;
int32* var p = addressof(value); // can reassign p, cannot modify *p
var int32* q = addressof(mutable_value); // cannot reassign q, can modify *q
var int32* var r = addressof(mutable_value); // can reassign r, can modify *r