Tutorial by Examples

Methods in Go are just like functions, except they have receiver. Usually receiver is some kind of struct or type. package main import ( "fmt" ) type Employee struct { Name string Age int Rank int } func (empl *Employee) Promote() { empl.Rank++ } ...
With methods in golang you can do method "chaining" passing pointer to method and returning pointer to the same struct like this: package main import ( "fmt" ) type Employee struct { Name string Age int Rank int } func (empl *Employee) Promote() *...
Though Go supports ++ and -- operators and the behaviour is found to be almost similar to c/c++, variables with such operators cannot be passed as argument to function. package main import ( "fmt" ) func abcd(a int, b int) { fmt.Println(a," &...

Page 1 of 1