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.7k Golang : Random integer with rand.Seed() within a given range
+7.8k Golang : Handle sub domain with Gin
+11k Golang : 2 dimensional array example
+25.1k Golang : Encrypt and decrypt data with AES crypto
+4.1k Swift : Convert (cast) Float to Int or Int32 value
+26.5k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+6.3k Golang : alternative to os.Exit() function
+6.5k Golang : Handling Yes No Quit query input
+11.9k Golang : List objects in AWS S3 bucket
+12k Golang : Linear algebra and matrix calculation example
+8.4k Golang : Get all countries currencies code in JSON format
+32.4k Golang : How to check if slice or array is empty?