Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Behavior of defer function in named return function

In Go, there is a special concept of named return value in function where a returned value can have name. For example, below is a named function in Go.func returnNamed() (i int) { i = 1 return}When the function returns, the return value i will have a value of 1. Also, Go has a concept of defer which will execute a function just before the calling function exits. This is similar to what finally block does in other languages such as Java. For example, a defer function can befunc deferFunc() { defer func() { fmt.Println("In defer") }() fmt.Println("Start")}Both return and defer can change th...

3,864 0       GOLANG DEFER NAMED RETURN DIFFERENCE