Core Features

Variables

Learn about variables in Cambo.

Declaration & Initialization

syntax
# declare
type variable_name;
syntax
# assign a value
variable_name = value;
syntax
# declare + initialize
type variable_name = value;

If a variable is declared without initialization, the compiler automatically assigns a default value to it. Default values for each corresponding type are listed below

typedefault value
integer0
floating-point0.0
pointernull
character'\0'
string"", '\0'
booleanfalse
regular expression\\
enumnone*
structnone*

Basic types

In Cambo, there are many different kinds of data types, however here are some basic ones:

int
Stores integers, whole number, such as 1975 or -1975.
float
Stores floating point numbers, with decimals, such as 19.70 or - 19.70.
bool
Stores values with two state: true or false.
char
Stores single characters, such as 'A', or 'a'.
string
Stores text, such as "Khmer", strings are surrounded by double quote "".
string is not originally a primitive data type, it's a built-in struct in Cambo. See data types page.

Example

1. Declare & initialize:

int main(){
  
  int number = 3; 
  float pi = 3.14;
  bool running = false;
  char symbol = 'A';
  string text = "hello, world!";
  
  return 0;
}

2. Declare without initialization:

int main(){

  int number;
  print(number); # output: 0

  bool running;
  print(running); # output: false

  return 0;
}

3. Declare then initilialize later:

int main(){

  int number; 
  number = 3;

  return 0;
}

To be precise, when a variable is declared without an explicit initilizer, the compiler automatically assigns a default value behind the scenes. As a result, initializing a value later is always an explicit reassignment, not an initial initialization. This means that initialization only occurs at the point of declaration.
As shown in third example above, the variable number is already initialized to 0 at the declaration line int number; by the compiler. The line number = 3; is simply a reassignment of the variable number to the value of 3.
However, the compiler may optimize this by initializing number directly to 3, removing the default initialization to 0.

Although variables have default values, explictly initialization is always a good practice.
Copyright © 2026