create, use and destroy a 2d array
PROGRAM Example
IMPLICIT NONE
INTEGER :: rows, columns, errcheck
INTEGER, ALLOCATABLE :: array(:,:)
rows = 5
columns = 10
ALLOCATE (array(rows,columns), STAT=errcheck) ! STAT is optional and is used for error checking
array(3, 3) = 999
WRITE(*,*) array(3, 3)
DEALLOCATE (array, STAT=errcheck)
END PROGRAM Example
3.67
9
package main
import "fmt"
func main() {
rows := 5
columns := 10
slice_of_slices := make([][]int , rows)
for i := 0; i < rows; i++ {
slice_of_slices[i] = make([]int, columns)
for j := 0; j < rows; j++{
slice_of_slices[i][j] = i * j
}
}
slice_of_slices[3][3] = 999
fmt.Println("Slice of slices: ", slice_of_slices[3][3])
// Automatically deallocates when out of scope.
}
Thank you!
9
0
Are there any code examples left?
New code examples in category Fortran
-
Fortran 2021-11-15 03:21:30 herf downloadin html
-
Fortran 2021-11-08 14:09:09 do loop fortran
-
Fortran 2021-11-05 08:19:08 fortran module
-
Fortran 2021-10-29 23:22:08 fortran do while
-
Fortran 2021-10-24 19:48:10 fortran exp function
-
Fortran 2021-09-16 06:02:04 fortran select case