![]() |
VOOZH | about |
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.
Output:
&{10 20 Green}
&{10 0 Red}
10
Red
&{0 10 Blue}