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 found in hexadecimal format(starting with 0x like 0xFFAAF etc.).
In Go language, you are allowed to compare two pointers with each other. Two pointers values are only equal when they point to the same value in the memory or if they are nil. You can perform a comparison on pointers with the help of == and != operators provided by the Go language:
1. == operator: This operator return true if both the pointer points to the same variable. Or return false if both the pointer points to different variables.
pointer_1 == pointer_2
Is p1 pointer is equal to p2 pointer: false Is p1 pointer is equal to p2 pointer: false Is p1 pointer is equal to p3 pointer: true Is p2 pointer is equal to p3 pointer: false Is p3 pointer is equal to p1 pointer: false
2. != operator: This operator return false if both the pointer points to the same variable. Or return true if both the pointer points to different variables.
pointer_1 != pointer_2
Is p1 pointer not equal to p2 pointer: true Is p1 pointer not equal to p2 pointer: true Is p1 pointer not equal to p3 pointer: false Is p2 pointer not equal to p3 pointer: true Is p3 pointer not equal to p1 pointer: true
- Comparing Maps in Golang
- Pointers in Golang
- Pointers to a Function in Go
- Zero value in Golang
- Reflection in Golang
- How to copy a map to another map in Golang?
- Packages in Golang
- Slices in Golang
- Rune in Golang
- Encapsulation in Golang
- Composition in Golang
- What is Regex in Golang?
- Strings in Golang
- Golang Maps
- Structures in Golang
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.