Go fundamentals pt1
Table of contents
No headings in the article.
package main
//all go files in a same folder must have same pkg name
import "fmt"
func main() {
fmt.Println("hello gopher!")
}
The build file is big 1.8 MB for a simple hellworld prog because it contains Runtime information, GC, Scheduler (its like whole python, jvm in an executable) It is statically linked: it does not depend on shared library.
Default is pass by value in go. To use reference use * (get underlying value) and &(get memory address ). Pass by value will copy the value, Pass by reference will give the memory location.
a := "hello"
b := a
b = "world"
fmt.Println(a) // Output: "hello"
fmt.Println(b) // Output: "world"
In the example above, b
is assigned a new value "world", but the value of a
remains unchanged at "hello". This is because the two variables are separate copies of the same value, and changes to one do not affect the other.