Introducing Go by Caleb Doxsey

Introducing Go by Caleb Doxsey

Author:Caleb Doxsey
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media, Inc.
Published: 2016-01-21T16:00:00+00:00


package main import "fmt" func main() { defer func() { str := recover() fmt.Println(str) }() panic("PANIC") }

A panic generally indicates a programmer error (e.g., attempting to access an index of an array that’s out of bounds, forgetting to initialize a map, etc.) or an exceptional condition that there’s no easy way to recover from (hence the name panic).

Pointers

When we call a function that takes an argument, that argument is copied to the function:

func zero(x int) { x = 0 } func main() { x := 5 zero(x) fmt.Println(x) // x is still 5 }

In this program, the zero function will not modify the original x variable in the main function. But what if we wanted to? One way to do this is to use a special data type known as a pointer:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.