Confused as to why the below is happening. TLDR; I'm passing a pointer and a "&val" to database/sql 's Scan method, and getting different results
rows, err := db.Query(selectRowsQuery)
val = new(int)
for rows.Next() {
err = rows.Scan(val)
...
fmt.Println(val) // 0xc0000b6c48
Val's value is a pointer. Why does val stay as a pointer?
but if I do this:
var val int
...
err = rows.Scan(&val)
fmt.Println(val) // 0
val returns as the value. Aren't "&val" (val is an int value) and "val" (val is a pointer to int) the same thing?
fmt.Println(*val)