package main
import "fmt"
var i int = 20
fmt.Println(i)
func main() {
var i int = 10
fmt.Printf("i Value: %d\ti address: %p\n", i, &i)
}
I get an error stating the following:
main.go|6 col 1| : expected declaration, found fmt
main.go|10 col 2| : expected declaration, found fmt
I am trying to print the value and address of the variable i
While I know that the i in the main is different than the i in the main, printing it out is something that’s not working. If the i in the main is commented, then it works well.
What am I missing? Is fmt.Println or fmt.Printf not designed to work outside of a block? Or am I missing something fundamental ?
Hi Yamil,
Thanks for the update. How did you get so much knowledge? Did you go through any specific book or online course? Or just practice and experience?