Create a two-dimensional array at runtime: Difference between revisions
Content added Content deleted
(Updated D entry) |
No edit summary |
||
Line 1,493: | Line 1,493: | ||
2 3 r@ 2D-get-element #! Get the element at 2,3 |
2 3 r@ 2D-get-element #! Get the element at 2,3 |
||
r> drop #! Discard the pointer to the array</lang> |
r> drop #! Discard the pointer to the array</lang> |
||
=={{header|XPL0}}== |
|||
<lang XPL0>inc c:\cxpl\codes; \(command words can be abbreviated to first 3 letters) |
|||
def IntSize=4; \number of bytes in an integer (2 or 4 depending on version) |
|||
int X, Y, A, I; |
|||
[X:= IntIn(0); Y:= IntIn(0); \get 2 dimensions from user |
|||
A:= Reserve(X*IntSize); |
|||
for I:= 0 to X-1 do A(I):= Reserve(Y*IntSize); |
|||
A(X/2, Y/2):= X+Y; |
|||
IntOut(0, A(X/2, Y/2)); CrLf(0); |
|||
]</lang> |
|||
Space allocated by the Reserve intrinsic is automatically released when |
|||
the procedure that calls Release returns. |
|||
Example of a 12000x100 integer array for a total of 1.2 million integers: |
|||
<pre> |
|||
12000 100 |
|||
12100 |
|||
</pre> |