This is just something that caught my curiosity.
While we know that in C/C++ returning a local non-pointer type variable declared in a function is illegal, this is perfectly legal in Golang. Why is that so? Does the compiler determines whether to allocate the variable to stack/heap during compile time based on the usage of the variable?
for example
func getVal() *int {
x := 1
return &x
}