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
+20.7k Golang : Match strings by wildcard patterns with filepath.Match() function
+10.6k Golang : Change date format to yyyy-mm-dd
+3.2k Detect if Google Analytics and Developer Media are loaded properly or not
+12.9k Golang : concatenate(combine) strings
+17k Golang : Get download file size
+20.3k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+27.3k Golang : Detect (OS) Operating System
+26.6k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+42.7k Golang : Use wildcard patterns with filepath.Glob() example
+12.7k Golang : Gin framework accept query string by post request example
+35.7k Upload multiple files with Go
+14.3k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type