
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.
Get two integers from the user, then create a two-dimensional array where the two dimensions have the sizes given by those numbers, and which can be accessed in the most natural way possible. Write some element of that array, and then output that element. Finally destroy the array if not done by the language itself.

 
MODULE TestArray;
(* Implemented in BlackBox Component Builder *)
 
	IMPORT Out;
 
	(* Open array *)
 
	PROCEDURE DoTwoDim*;
		VAR d: POINTER TO ARRAY OF ARRAY OF INTEGER;
	BEGIN
		NEW(d, 5, 4); (* allocating array in memory *)
		d[1, 2] := 100; (* second row, third column element *)
		d[4, 3] := -100; (* fifth row, fourth column element *)
		Out.Int(d[1, 2], 0); Out.Ln;
		Out.Int(d[4, 3], 0); Out.Ln;
	END DoTwoDim;
 
END TestArray.