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
Tshepo 105 points

                                    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.
}

3.67 (9 Votes)
0
Are there any code examples left?
New code examples in category Fortran
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source