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
+13.3k Golang : Strings comparison
+8.8k Golang : Serving HTTP and Websocket from different ports in a program example
+7k Golang : File system scanning
+7.5k Golang : Reverse a string with unicode
+7.8k Findstr command the Grep equivalent for Windows
+7.5k Golang : get the current working directory of a running program
+6.8k Golang : Find the shortest line of text example
+86.1k Golang : How to convert character to ASCII and back
+14k Golang : Get uploaded file name or access uploaded files
+45.7k Golang : Read tab delimited file with encoding/csv package
+9.2k Golang : Extract or copy items from map based on value