Golang Pointer to an Array as Function Argument Last Updated : 22 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: Pointers in Golang Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Whereas an array is a fixed-length sequence which is used to store homogeneous elements in the memory. You can use the pointers to an array and pass that one as an argument to the function. To understand this concept let's take an example. In the below program we are taking a pointer array arr which has 5 elements. We want to update this array using a function. Means modifying the array(here the array is {78, 89, 45, 56, 14}) inside the function and that will reflect at the caller. So here we have taken function updatearray which has pointer to array as argument type. Using updatearray(&arr) line of code we are passing the address of the array. Inside function (*funarr)[4] = 750 or funarr[4] = 750 line of code is using dereferencing concept to assign new value to the array which will reflect in the original array. Finally, the program will give output [78 89 45 56 750]. C // Golang program to pass a pointer to an // array as an argument to the function package main import "fmt" // taking a function func updatearray(funarr *[5]int) { // updating the array value // at specified index (*funarr)[4] = 750 // you can also write // the above line of code // funarr[4] = 750 } // Main Function func main() { // Taking an pointer to an array arr := [5]int{78, 89, 45, 56, 14} // passing pointer to an array // to function updatearray updatearray(&arr) // array after updating fmt.Println(arr) } Output: [78 89 45 56 750] Note: In Golang it is not recommended to use Pointer to an Array as an Argument to Function as the code become difficult to read. Also, it is not considered a good way to achieve this concept. To achieve this you can use slice instead of passing pointers. Example: C // Golang program to illustrate the // concept of passing a pointer to an // array as an argument to the function // using a slice package main import "fmt" // taking a function func updateslice(funarr []int) { // updating the value // at specified index funarr[4] = 750 } // Main Function func main() { // Taking an slice s := [5]int{78, 89, 45, 56, 14} // passing slice to the // function updateslice updateslice(s[:]) // displaying the result fmt.Println(s) } Output: [78 89 45 56 750] Comment More infoAdvertise with us A anshul_aggarwal Follow Improve Article Tags : Go Language Golang-Pointers Golang Similar Reads Go Tutorial Go or you say Golang is a procedural and statically typed programming language having the syntax similar to C programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language and mainly used in Google 2 min read Go Programming Language (Introduction) Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports env 11 min read time.Sleep() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Sleep() function in Go language is used to stop the latest go-routine for at least the stated duration d. And a negative or zero duration of sleep will cause this method to return instantly. Moreover, t 3 min read Golang Tutorial - Learn Go Programming Language This Golang tutorial provides you with all the insights into Go Language programming, Here we provide the basics, from how to install Golang to advanced concepts of Go programming with stable examples. So, if you are a professional and a beginner, this free Golang tutorial is the best place for your 10 min read Top 10 Golang Project Ideas with Source Code in 2025 Golang, or Go, a programming language was created by Google. It's widely used for building different kinds of applications like websites and cloud services. The fastest way to master this language is by building projects related to it. This article introduces 10 beginner-friendly to medium-difficult 8 min read Interfaces in Golang In Go, an interface is a type that lists methods without providing their code. You canât create an instance of an interface directly, but you can make a variable of the interface type to store any value that has the needed methods.Exampletype Shape interface { Area() float64 Perimeter() float64}In t 3 min read Top 10 Golang Frameworks in 2025 Golang (or Go) is an open-source compiled programming language that is used to build simple, systematic, and secure software. It was designed by Google in the year 2007 and has been readily adopted by developers all over the world due to its features like memory safety, structural typing, garbage co 9 min read strings.Contains Function in Golang with Examples strings.Contains Function in Golang is used to check the given letters present in the given string or not. If the letter is present in the given string, then it will return true, otherwise, return false. Syntax:Â func Contains(str, substr string) bool Here, str is the original string and substr is t 2 min read Data Types in Go Data types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows: Basic type: Numbers, strings, and booleans come under this category.Aggregate type: Array and structs come under this category.Reference type: Pointer 7 min read fmt.Sprintf() Function in Golang With Examples In Go language, fmt package implements formatted I/O with functions analogous to C's printf() and scanf() function. The fmt.Sprintf() function in Go language formats according to a format specifier and returns the resulting string. Moreover, this function is defined under the fmt package. Here, you 2 min read Like