Variable Declaration
Declaring a variable is the process of naming a memory to make possible access (Read/Write) to that location.
In order to declare a
variable you first specify the memory type and then the name of the variable.
Look at the following examples:
Integer i
i = 5
i = i * 2
Float f
f = 2.5
f = f / 4
String str
str = "Hello World!"
Matrix mat[3][4]
mat = [ 1 ; 2 ; 3 ; 4 ;;
5 ; 6 ; 7 ; 8 ;;
-1 ;-2 ;-3 ; -4 ]
mat[2] = [-5 ; -6; -7;-8]
mat[2][3] = [7]
Multiple Declaration:
Many variables may be
declared within a single statement, by using a comma to separate them.
Look at the following example:
Integer i , j , k
i = 5
j = i * 4 + 3
k = j - i
Array Declaration:
An array is a sequentially indexed set of a number of variables of the same type.
Any variable may be
declared as an array of any size by using a brackets to specify the number of
elements.
Look at the following example:
Integer v[10] , i
v[1] = 5
v[2] = -16
i = 5
v[i] = 23
v[i*2] = -4
Dynamic Arrays:
A dynamic array is the one whose size is not determined or obvious when writing the program. Hence, variable in size. Declaring dynamic arrays is so easy in MEHRANN. Array size can be a fixed number or a variable.
Look at the following example:
Integer n
....
....
....
n = 60 * tan(x) / abs(x)
....
....
....
Integer v[n]
....
....
....