alt
codecamp
Golang Essentials: Pointers
Previous
Next
☰
About
Profile
Account
Login
Sign Up
Logout
Run
Test
Mark Complete
## Pointers in Go Pointers in Go are variables that store the memory address of another variable. Pointers are powerful and can be used to modify the value of the variable they point to. ### Declaring Pointers A pointer is declared using the `*` symbol before the type. To get the address of a variable, use the `&` symbol: ```go var a int = 42 var b *int = &a ``` In this example, `b` is a pointer to an `int` and holds the address of `a`. ### Dereferencing Pointers Dereferencing a pointer means accessing the value at the address the pointer is pointing to, done using the `*` symbol: ```go var value int = *b // value is now 42 ``` ### Pointers in Functions Pointers can be passed to functions, allowing the function to modify the value of the original variable: ```go func modifyValue(p *int) { *p = 10 } ``` ### Conclusion Understanding pointers is crucial in Go, as they allow you to control and manipulate data stored in memory locations directly.