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.3k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+7.9k Golang : Reverse a string with unicode
+6.1k nginx : force all pages to be SSL
+11.6k CodeIgniter : Import Linkedin data
+24.5k Golang : Change file read or write permission example
+21.7k Golang : Encrypt and decrypt data with TripleDES
+8k Javascript : Put image into Chrome browser's console
+10.3k Golang : Text file editor (accept input from screen and save to file)
+15.9k Golang : Get digits from integer before and after given position example
+14.9k Golang : Normalize unicode strings for comparison purpose
+14.7k Golang : GUI with Qt and OpenCV to capture image from camera
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine