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
+8.3k Useful methods to access blocked websites
+13.5k Golang : Strings comparison
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+14.5k Golang : GUI with Qt and OpenCV to capture image from camera
+22.1k Golang : Repeat a character by multiple of x factor
+11.1k Golang : Calculate Relative Strength Index(RSI) example
+17.1k Golang : Find file size(disk usage) with filepath.Walk
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+17.6k Golang : delete and modify XML file content
+8.9k Golang : Go as a script or running go with shebang/hashbang style
+10.9k Golang : Create Temporary File
+16.3k Golang :Trim white spaces from a string