The int statement is used to define one or more variables of type int. This means that a 16 bit memory location is reserved for use by the program and that the location is given the symbolic name specified by the programmer. Variables of type int are used to store numbers in the range -32768 to +32767Any number of variables may be defined in one int statement
e.g. int var1 int var1, var2, var3The int statement may also be used to define arrays of ints. An array of ints is a special variable which can be used to store more than one value at the same time. Each value is refered to by an index (the index is a number). An array of ints is defined as:int var1[10]The name used (here it is var1) is completely at the discretion of the programmer, it can be anything other than a reserved word. The [10] part of the statement means allocate space for 10 values. So unlike a normal variable definition which only assigns space for 1 value and array definition also specifies how many values space must be reserved for. Zero 0 is also allowed and provides special possibilities.
Any combination of variables and arrays may be defined in a single int statement.
e.g. int var1[10], var2, var3[7], var99The int statement has two forms. Both forms seem identical however the behaviour is dependent of the context in which the statement is used.
- If the int statement is used inside a function definition then the statement defines one or more local variables of type int.
- if the int statement is used outside all function definitions then the statement defines one or more global variables of type int.
e.g. proc fred() // here the int statement defines a variable called var1 // which is local to the function fred // NOTE: var1 that belongs to function fred is not the same // var1 that belongs to function jack int var1 endproc proc jack() // here the int statement defines a variable called var1 // which is local to the function jack // NOTE: var1 that belongs to function fred is not the same // var1 that belongs to function jack int var1 endproc proc bert() // here the int statement defines a variable called var2 // which is local to the function bert // NOTE: var2 that belongs to function bert can only be // seen by function bert, function freds and jack cannot // see the var2 that belongs to function bert int var2 endproc // here the int statement defines a global called var1 // which cannot be seen by functions fred and jack since // they have local variables with the same name. // however function bert can see and use this global variable // called var1 int var1