Introduction Flashcards

1
Q

Strings are ___ indexed in Go

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Integer types in Go

A

uint8, uint16, uint32, uint64, int8, int16, int32, and int64

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Three logical operators in Go

A

&& - and, || - or, ! - not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Rules for naming variables in Go

A
  1. Start with a latter

2. Can contain letters, numbers and _

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Keyword for declaring a variable in Go

A

var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Keyword for declaring a constant in Go

A

const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Two ways of declaring variables in Go

A
  1. Using the var keyword inline

2. Using the var keyword with a block [ var (…) ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What scoping rules does Go use?

A

Lexcial scoping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What options are available for controlling flow in Golang?

A

for, if and switch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How should you write a while loop in Go?

A

for {…} or for true {…}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between “” and `` in Go?

A

Strings created from “” can contain only escape sequences. Strings created from `` can contain new lines and other literal.s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are arrays initialized in go

A

var []

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The ____ function can be used to find the length of arrays and strings in Go

A

len

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

To convert between types in Go, you ______

A

Use the type names like a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

We use the keyword _____ followed by the name of the variable we want to loop over

A

range

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

A _______ is used to tell the compiler that we don’t need this variable

A

single underscore (_)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Short syntax for creating arrays in Go

A

[]{…items…}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The length of the slice type in Go is constant. True or false?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the ways in which you can create a slice in Go?

A
  1. Using the make function

2. Indexing arrays (arr[low: high])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the arguments to the copy function?

A

dst (destination) and src (source)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How should maps be created in Go?

A

var := make(map[])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The _____ function can be used to delete items from a map

A

delete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a variadic parameter?

A

A parameter which can be used to accept multiple arguments of a single type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to define

A

func (args …) {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
The ____ keyword can be used to move a function call to the end
defer
26
Deferred function calls happen before the function returns. True of false?
True
27
Deferred functions are run even if a runtime panic occurs. True or false?
True
28
In Go, arguments are passed by value by default unless pointers are used. True or false?
True
29
In Go, a pointer is represented using an ______ followed by the type of the storedvalue
asterisk
30
An asterisk is also used to dereference pointer variables. Dereferencing a pointer givesus access to the value the pointer points to. True or false?
True
31
What's the difference between * and & in go?
* indicates that the object in question is a pointer of type . & is how this pointer is obtained.
32
The _____ function takes a type as an argument, allocates enough memory to fit a value of that type,and returns a pointer to it.
new
33
We can access fields of a struct using the ____ operator
.
34
Embedded types in Go are an implementation of inheritance. True or false?
True
35
How are embedded types defined?
type struct { ...fields }
36
A _______ is a list of methods that a type must have in order to implement the inter‐face.
method set
37
What is a struct?
A struct is a container which contains has-a/is-a relationships.
38
What is an interface?
An interface is a container which defines a bunch of methods which can be called.
39
How are structs and interfaces related to each other?
If a struct is said to implement an interface, then the struct implements all the methods that the interface defines.
40
To search for a smaller string in a bigger string, use the ____ function
strings.Contains
41
To count the number of times a smaller string occurs in a bigger string, use the ______ function
strings.Count
42
To determine if a bigger string starts with a smaller string, use the ______ function
strings.HasPrefix
43
To determine if a bigger string ends with a smaller string, use the _____ function
strings.HasSuffix
44
To find the position of a smaller string in a bigger string, use the _______ function
strings.Index
45
To take a list of strings and join them together in a single string separated by anotherstring (e.g., a comma), use the __________ function
strings.Join
46
To repeat a string, use the _________ function
strings.Repeat
47
To replace a smaller string in a bigger string with some other string, use the _______ function, which also takes a number indicating how many times to do the replacement
strings.Replace
48
To split a string into a list of strings by a separating string (e.g., a comma), use the function
strings.Split
49
To convert a string to all lowercase letters, use the function
strings.ToLower
50
To convert a string to all uppercase letters, use the function
strings.ToUpper
51
To convert a string to a slice of bytes use the _____ function
byte
52
the io package has a ____ function that copies data from a Reader to a Writer
Copy
53
To read or write to a []byte or a string, you can use the ______ struct found in the ______ package:
Buffer, bytes
54
You can convert a Buffer into a []byte by calling ________
Buffer.Bytes()
55
To open a file in Go, use the _____ function from the __ package
Open, os
56
The _____ function from the ____ package serves as a shortcut to opening files using os.Open
ioutil.ReadFile
57
To create a file, use the _________ function.
os.Create
58
To get the contents of a directory, we use the same os.Open function but give it adirectory path instead of a file name. Then we call the ______ method
Readdir
59
The _____ function can be used to perform a specific set of operations (defined in a function) on each file and folder in a directory. The registered function is passed three arguments: ____, ____ and ___ for each file/folder in the directory.
os.Walk, path of the file, info of the file and err
60
We can create our own errors by using the _____ function in the _____ package
New, errors
61
The _____ package contains functions for sorting arbitrary data.
Sort
62
The non-cryptographic hash functions can be found underneath the ____ package
hash
63
The cryptographic hash functions can be found underneath the ____ package
crypto
64
In Go, we can create a TCP server using the ____ package’s _____ function
net, Listen
65
The ____ package allows us to parse arguments and flags sent to our program.
flag
66
To create a goroutine, we use the keyword ____ followed by a _________
go, function invocation