Golang : Valued expressions and functions example
Writing this simple example down here as a reminder for myself on how to use valued expressions in Golang. Nothing complicated, just a simple reminder for my old brain.
Here you go!
package main
import (
"fmt"
)
func main() {
// functions
g := func(x int) int { return x * 9 }
f := func() int { return 9 }
fmt.Println(g(f()))
// arithmetic
fmt.Println("One plus five is ", 1+5)
value := 2
fmt.Println(value * 2) // 4
fmt.Println(float64(value*16) / 2)
}
Output :
81
One plus five is 6
4
16
See also : Golang : Display list of time zones with GMT
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.6k Golang : Sort lines of text example
+20.5k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+12k Swift : Convert (cast) Int to String ?
+7.8k Golang : How to use Gorilla webtoolkit context package properly
+14.5k Golang : Update database with GORM example
+23.6k Golang : Convert long hexadecimal with strconv.ParseUint example
+20.5k Golang : How to reverse slice or array elements order
+72.1k Golang : How to return HTTP status code?
+11.3k Golang : Covert map/slice/array to JSON or XML format
+11.5k Golang : Transform comma separated string to slice example
+9.2k Golang : Meaning of omitempty in struct's field tag
+5.7k Golang : Output or print out JSON stream/encoded data