Variables and types - LucasMW/mongaComp GitHub Wiki

Variables and types

Monga has three base types: int, float and char

Variables are declared like this:

int i;
float f;
char c;

Variables with the same type can also be declared like this:

int x,y,z;

and it is equivalent to this

int x;
int y;
int z;

Variables can only be declared at the beginning of a scope and before their use:

correct:

 int f(int a) {
 int x,y;
 x = a;
 y = a+3;
 x = x+y;
 return x+1;
}

wrong:

int f(int a) {
 int x;
 x = a;
 int y;
 y = a+3;
 x = x+y;
 return x+1;
}

variables are assigned with values of their type:

int x;
float y;
x = 5+x;
y = 2.0;

variables of type char can be assigned with ints and vice versa:

int x,y;
char c;
x = c;
c = y;

There is still the array type. An array is always a array of another type

int[] arrayOfIntegers;
float[] arrayOfFloats;
int[][] arrayOfArrayOfIntegers;

Go to the arrays section for more information.