Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8856125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:17:21+00:00 2026-06-14T14:17:21+00:00

Is it possible to use range and len on a multidimensional array? Either with

  • 0

Is it possible to use range and len on a multidimensional array?

Either with var a [3]int8 or

package main

func main () {    
        var a [3][5]int8

        for h := range a {
                println(h)
        }
        println(len(a))
}

Both produce

0
1
2
3

?

Thanks to dystroy’s answer, here’s an example of writing and reading a 3-dimensional array i was able to adapt (posting here because I had much trouble finding any examples of this, so maybe this will help someone else):

package main
func main() {
    var a [3][5][7]uint8

    //write values to array
    for x, b := range a {
        for y, c := range b {
            for z, _ := range c {
                    a[x][y][z] = uint8(x*100+y*10+z)
                }
        }   
    }

    //read values from array
    for _, h := range a {
        for _, i := range h {
            for _, j := range i {
                print(j, "\t")
            }
            println()
        }
        println()
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:17:23+00:00Added an answer on June 14, 2026 at 2:17 pm

    In Go as in most languages, what you call a multidimensional array is an array of arrays. The len operator only gives you the length of the “external” array.

    Maybe the var declaration could be clearer for you if you see it as

    var a [3]([5]int8)
    

    which also compiles. It’s an array of size 3 whose elements are arrays of size 5 of int8.

    package main
    import "fmt"
    func main() {
        var a [3][5]int8
        for _, h := range a {
            fmt.Println(len(h)) // each one prints 5
        }
        fmt.Println(len(a))  // prints 3, the length of the external array
    }
    

    outputs

    5
    5
    5
    3
    

    To loop safely through the whole matrix, you can do this :

    for _, h := range a {
        for _, cell := range h {
            fmt.Print(cell, " ")
        }
        fmt.Println()
    }
    

    If you need to change the content, you may do

        for i, cell := range h { // i is the index, cell the value
            h[i] = 2 * cell
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to use geom_ribbon from the package ggplot2, but with the range
Is it possible to use [Range] annotation for dates? something like [Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())]
Is it possible to use or adapt jQuery's .select() to set a selection range
is it possible to use System.ComponentModel.DataAnnotations and it's belong attribute(such as Required , Range
Is it possible to use the JQuery Slider (range slider / dual slider) to
Possible Duplicate: Is there a range class in C++11 for use with range based
Is it possible to use a cell to define the end of a range
Why it is possible to use this: from r1 in Enumerable.Range(1, 10) join q1
Is it possible to use the ASP.Net Range validator when the format string is
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.