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
+6k Mac/Linux/Windows : Get CPU information from command line
+15.7k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+10.1k Golang : Generate random elements without repetition or duplicate
+7.1k Golang : Load DSA public key from file example
+17.7k Golang : Padding data for encryption and un-padding data for decryption
+7.8k Golang : How to join strings?
+10.2k Golang : Intercept and process UNIX signals example
+18.7k Golang : Convert seconds to human readable time format example
+9.2k Golang : Convert octal value to string to deal with leading zero problem
+10.4k Golang : How to pipe input data to executing child process?
+13.7k Golang : Rename directory
+20.4k Golang : Convert(cast) string to rune and back to string example