Saturday, 4 May 2019

Go language: Anonymous functions


Function without name is called anonymous function.

Example
add := func(a int, b int) int{
         return a + b
}

HelloWorld.go
package main

import "fmt"

func main() {

 add := func(a int, b int) int{
  return a + b
 }

 result := add(10, 20)

 fmt.Println("result : ", result)

}

Output
result :  30



Previous                                                 Next                                                 Home

No comments:

Post a Comment