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
+18.8k Golang : Read directory content with os.Open
+11.2k Golang : Search and extract certain XML data example
+13.2k Golang : Reset buffer example
+16.1k Golang : delete and modify XML file content
+4.4k PHP : Fix Call to undefined function curl_init() error
+25.8k Golang : Convert CSV data to JSON format and save to file
+16.3k Golang : Login and logout a user after password verification and redirect example
+25.5k PHP : Convert(cast) string to bigInt
+15.4k Golang : File path independent of Operating System
+22.4k Golang : Use regular expression to validate domain name
+4.4k Javascript : How to loop over and parse JSON data?
+21.4k Golang : Test file read write permission example