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
+9.5k Golang : Gorilla web tool kit secure cookie example
+13.9k Golang : Get sub string example
+10.3k Golang : Count number of runes in string
+3.7k Golang : The Tao of importing package
+12.2k Golang : Get timezone offset from date or timestamp
+3.7k PHP : See installed compiled-in-modules
+10k Golang : How to parse plain email text and process email header?
+6.1k Golang : Handle Palindrome string with case sensitivity and unicode
+5.3k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+22.9k Golang : Force your program to run with root permissions
+7.1k Golang : HTTP Routing with Goji example
+13.6k Golang : How to extract links from web page ?