How to instantiate Struct Pointer Address Operator in Golang? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report As pointers are the special variables that are used to store the memory address of another variable whereas, the struct is user-defined data type that consists of different types. A struct is mainly a holder for all other data types. By using a pointer to a struct we can easily manipulate/access the data assigned to a struct. To use pointer to a struct we use "&" i.e, address operator. In Go lang, by using pointers to a struct we can access the fields of a struct without de-referencing them explicitly. Example: Here we have defined one struct names as "shape" and we are passing the values to the field of this struct. Also, we are printing the value of the struct using pointers. Go // Golang program to show how to instantiate // Struct Pointer Address Operator package main import "fmt" type shape struct { length int breadth int color string } func main() { // Passing all the parameters var shape1 = &shape{10, 20, "Green"} // Printing the value struct is holding fmt.Println(shape1) // Passing only length and color value var shape2 = &shape{} shape2.length = 10 shape2.color = "Red" // Printing the value struct is holding fmt.Println(shape2) // Printing the length stored in the struct fmt.Println(shape2.length) // Printing the color stored in the struct fmt.Println(shape2.color) // Passing only address of the struct var shape3 = &shape{} // Passing the value through a pointer // in breadth field of the variable // holding the struct address (*shape3).breadth = 10 // Passing the value through a pointer // in color field of the variable // holding the struct address (*shape3).color = "Blue" // Printing the values stored // in the struct using pointer fmt.Println(shape3) } Output: &{10 20 Green} &{10 0 Red} 10 Red &{0 10 Blue} Comment More infoAdvertise with us Next Article How to check pointer or interface is nil or not in Golang? P pganesh Follow Improve Article Tags : Go Language Write From Home Golang-Pointers Golang-Program Similar Reads How to instantiate Struct using new keyword in Golang? A struct is mainly a holder for all other data types. By using a pointer to a struct we can easily manipulate/access the data assigned to a struct. We can instantiate Struct using the new keyword as well as using Pointer Address Operator in Golang as shown in the below example: Example: Here, you ca 1 min read How to create a Struct Instance Using a Struct Literal in Golang? A structure or struct in Golang is a user-defined data type which is a composition of various data fields. Each data field has its own data type, which can be a built-in or another user-defined type. Struct represents any real-world entity which has some set of properties/fields. For Example, a stud 4 min read How to check pointer or interface is nil or not in Golang? In Golang, nil check is frequently seen in GoLang code especially for error check. In most cases, nil check is straight forward, but in interface case, it's a bit different and special care needs to be taken. Here the task is to check pointer or interface is nil or not in Golang, you can check with 3 min read Pointer to a Struct in Golang In Go, structs are used to create custom data types that group different fields together. When working with structs, using pointers can be especially beneficial for managing memory efficiently and for avoiding unnecessary copying of data. A pointer to a struct allows you to directly reference and mo 3 min read How to find the length of the pointer in Golang? Pointers in Go programming language or Golang is a variable which is used to store the memory address of another variable. Pointers in Golang are also termed as the special variables. The variables are used to store some data at a particular memory address in the system. The memory address is always 2 min read How to Declare and Initialize an Array of Pointers to a Structure in C? Prerequisite: Structure in CArray in C In C language, arrays are made to store similar types of data in contiguous memory locations. We can make arrays of either primitive data types, like int, char, or float, or user-defined data types like Structures and Unions. We can also make arrays of pointers 8 min read Like