O'Reilly logo

Introducing Go by Caleb Doxsey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Answers

Appendix A. Chapter 1

  1. Whitespace is the space between characters made up of space, tab, and newline characters.

  2. A comment is a section of code ignored by the compiler that can be used as a note for anyone reading the code. The two types of comments are // (which goes to the end of the line) and /* */.

  3. The files in the fmt package would begin with package fmt.

  4. In order to use the Exit function from the os package, you would need to import the os package: import "os" and then invoke it with .: os.Exit().

  5. Modifying the program to print with your name:

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, my name is Caleb")
    }
    

Appendix A. Chapter 2

  1. Integers are stored on a computer by using a base-2, binary number system.

  2. The largest eight-digit number in binary is 255.

  3. Program that computes 32,132 × 42,452 and prints it to terminal:

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println(32132 * 42452)
    }
    
  4. A string is a sequence of characters. You can find the length of a string using the len function (len("a string")).

  5. The value of the expression is true.

Appendix A. Chapter 3

  1. Two ways to create a new variable are: var x = 5 or x := 5.

  2. The value of x after running the equation is 6.

  3. Scope is the range of places a variable can be used. Scope in Go is determined lexically using blocks, so look for the nearest curly braces.

  4. Unlike a variable, the value of a constant is determined at compile time and cannot change throughout the lifetime of a program.

  5. Program ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required