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.6k Golang : Dealing with struct's private part
+5k Golang : Calculate a pip value and distance to target profit example
+11.8k Golang : Verify Linux user password again before executing a program example
+30.9k Golang : Download file example
+40.6k Golang : Convert to io.ReadSeeker type
+17.7k Golang : Parse date string and convert to dd-mm-yyyy format
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+5.3k PHP : Hide PHP version information from curl
+22.4k Golang : Read directory content with filepath.Walk()
+8.5k Golang : Generate Datamatrix barcode
+30.9k error: trying to remove "yum", which is protected
+10.3k Golang : Wait and sync.WaitGroup example