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 ...

Get Introducing Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.