How to pass an Array to a Function in Golang? Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Go, arrays are used to store a fixed-length collection of data of the same type. To manage this data effectively, you may often need to pass arrays to functions. In this article we will learn "How to pass an Array to a Function in Golang".Example: Go package main import "fmt" // Function to calculate the average of an array func calculateAverage(arr [6]int, size int) int { var sum int for _, value := range arr { sum += value } return sum / size } func main() { scores := [6]int{67, 59, 29, 35, 4, 34} average := calculateAverage(scores, len(scores)) fmt.Printf("%d\n", average) } Output38 Explanation:In this example, the calculateAverage() function takes an array of integers and its size as arguments. It computes the average of the array elements and returns it. The main function initializes an array called scores and calls the average calculation function.Key Points:Array Declaration:Use the syntax var arrayName [size]type to declare an array.var numbers [5]int // An array of 5 integersPassing Arrays:In Go, arrays are passed to functions by value, meaning the function receives a copy of the array. Changes made inside the function do not affect the original array.Pointer to Modify Original Array:If you want to modify the original array, you should pass a pointer to it.func modifyArray(arr *[5]int) { for i := range arr { arr[i] += 10 // Increment each element by 10 }}Modifying an ArrayExample: Go package main import "fmt" // Function to increment each element of the array func incrementArray(arr *[5]int) { for i := range arr { arr[i]++ // Increment each element by 1 } } func main() { values := [5]int{1, 2, 3, 4, 5} // Modifying the array incrementArray(&values) fmt.Println("Incremented array:", values) } OutputIncremented array: [2 3 4 5 6] Passing arrays to functions in Go allows for efficient data management. Understanding how to pass and modify arrays will help you write effective Go programs. Comment More info A ankita_saini Follow Improve Article Tags : Go Language Go-Functions Golang Golang-Arrays Explore Go Tutorial 3 min read OverviewGo Programming Language (Introduction) 7 min read How to Install Go on Windows? 3 min read How to Install Golang on MacOS? 4 min read Hello World in Golang 3 min read FundamentalsIdentifiers in Go Language 3 min read Go Keywords 2 min read Data Types in Go 7 min read Go Variables 9 min read Constants- Go Language 6 min read Go Operators 9 min read Control StatementsGo Decision Making (if, if-else, Nested-if, if-else-if) 5 min read Loops in Go Language 5 min read Switch Statement in Go 2 min read Functions & MethodsFunctions in Go Language 3 min read Variadic Functions in Go 3 min read Anonymous function in Go Language 2 min read main and init function in Golang 2 min read What is Blank Identifier(underscore) in Golang? 3 min read Defer Keyword in Golang 3 min read Methods in Golang 3 min read StructureStructures in Golang 7 min read Nested Structure in Golang 3 min read Anonymous Structure and Field in Golang 3 min read ArraysArrays in Go 7 min read How to Copy an Array into Another Array in Golang? 3 min read How to pass an Array to a Function in Golang? 2 min read SlicesSlices in Golang 14 min read Slice Composite Literal in Go 3 min read How to sort a slice of ints in Golang? 2 min read How to trim a slice of bytes in Golang? 3 min read How to split a slice of bytes in Golang? 3 min read StringsStrings in Golang 7 min read How to Trim a String in Golang? 2 min read How to Split a String in Golang? 3 min read Different ways to compare Strings in Golang 2 min read PointersPointers in Golang 8 min read Passing Pointers to a Function in Go 3 min read Pointer to a Struct in Golang 3 min read Go Pointer to Pointer (Double Pointer) 4 min read Comparing Pointers in Golang 3 min read Like