Table of Contents

DIM

PET VIC-20 C64 C16 Plus/4 C128 X16 M65

DIM is used for defining variables and arrays.

Syntax

DIM|STATIC [SHARED] [FAST] _
<variable name>[(<array dimensions>)] AS <type> [@<address>] _
[, <variable name>[(<array dimensions>)] AS <type> [@<address>] ... ] _
[SHARED] [FAST] 

DIM is used to explicitly define variables and assign them a type. Since XC=BASIC is a statically typed programming language, all variables must be defined before they can be used. While some variables can be auto-defined by the compiler without the use of the DIM statement (known as “implicit definition”), the use of DIM ensures the variable is defined as the intended type.

Examples

' define single variables
DIM enemy_count AS INT
DIM score AS DECIMAL
DIM gravity AS FLOAT
DIM name$ AS STRING * 16

' define multiple variables in a single statement,
' all in the shared scope
DIM SHARED a AS INT, b AS WORD, c AS FLOAT

' dimension an array of 24 INT variables
DIM rockets(24) AS INT

' define a variable with explicit address
DIM my_var AS INT @ $C000

Additional Details

Note

Refer to the Variables page for more information on defining variables. Refer to the Data Types page for more information on variable types and their use.

See Also