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.2k Golang : A simple forex opportunities scanner
+5.7k Python : Print unicode escape characters and string
+20k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+10.1k Golang : Convert octal value to string to deal with leading zero problem
+9.1k Golang : Go as a script or running go with shebang/hashbang style
+16k Golang : Get current time from the Internet time server(ntp) example
+8.3k Golang : Add build version and other information in executables
+27.8k Golang : dial tcp: too many colons in address
+10.3k Golang : Bcrypting password
+19.3k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+5k JQuery : Calling a function inside Jquery(document) block