Pointer-to-Pointer

This program demonstrates how to use a pointer-to-pointer varibale to create a two-dimensional array.

'Pointer-to-Pointer Example
'Demonstrates how to create a two-dimensional array
'using a pointer-to-pointer variable.
'*******************************************************

'Declare a pointer to an int pointer
Dim myMemArray As Integer Ptr Ptr
Dim As Integer i, j

'Create 5 rows of integer pointers
myMemArray = Callocate(5, Sizeof(Integer Ptr))

'Add 5 columns of integers to each row
For i = 0 To 4
    myMemArray[i] = Callocate(5, Sizeof(Integer))
Next

'Add some data to the memory segment
For i = 0 To 4
    For j = 0 To 4
        myMemArray[i][j] = Int(Rnd * 10)
    Next
Next

'Print out data
For i = 0 To 4
    For j = 0 To 4
        Print "i,j = ";i;",";j;" Mem Array =";myMemArray[i][j]
    Next
Next

'Free memory segment
For i = 0 To 4
    Deallocate myMemArray[i]
Next
'Free the pointer to pointer
Deallocate myMemArray

Sleep
End