Appendix A. Answers
Appendix A. Chapter 1
Whitespace is the space between characters made up of space, tab, and newline characters.
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/* */
.The files in the
fmt
package would begin withpackage fmt
.In order to use the
Exit
function from theos
package, you would need to import theos
package:import "os"
and then invoke it with.
:os.Exit()
.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
Integers are stored on a computer by using a base-2, binary number system.
The largest eight-digit number in binary is 255.
Program that computes 32,132 × 42,452 and prints it to terminal:
package
main
import
"fmt"
func
main
()
{
fmt
.
Println
(
32132
*
42452
)
}
A string is a sequence of characters. You can find the length of a string using the
len
function (len("a string")
).The value of the expression is
true
.
Appendix A. Chapter 3
Two ways to create a new variable are:
var x = 5
orx := 5
.The value of
x
after running the equation is6
.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.
Unlike a variable, the value of a constant is determined at compile time and cannot change throughout the lifetime of a program.
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.