What is this ๐?
var favoriteNumber int = 7
a variable of the name "favoriteNumber" of a type integer that stores 7.
similarly
var favoriteColor string = "black"
a variable of the name "favoriteColor" of a type string that stores "black".
pretty simple right? ๐ค
How does computer store variables?
Computer store variable in the memory as block and block has an address and value. we can access and manipulate that value by address and here comes the pointer in the picture.
What is Pointer?
Pointer is a type of variable that contains the address of another variable.
// integer type variable
var num int = 7
// address of num stored in pointer p
var p *int = &num
fmt.Printf(p) // output: 0xc000018030
// yours will different
// access value of num by address
fmt.Printf(*p) // output: 7
// manipulate the value of num by address
*p = 18
fmt.Printf(num) // output: 18
For me, the pointer was a mysterious ๐๏ธโ๐จ๏ธ topic. Share your experience in the comments
ย