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
Q

The ____ keyword can be used to move a function call to the end

A

defer

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

Deferred function calls happen before the function returns. True of false?

A

True

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

Deferred functions are run even if a runtime panic occurs. True or false?

A

True

28
Q

In Go, arguments are passed by value by default unless pointers are used. True or false?

A

True

29
Q

In Go, a pointer is represented using an ______ followed by the type of the storedvalue

A

asterisk

30
Q

An asterisk is also used to dereference pointer variables. Dereferencing a pointer givesus access to the value the pointer points to. True or false?

A

True

31
Q

What’s the difference between * and & in go?

A
  • indicates that the object in question is a pointer of type . & is how this pointer is obtained.
32
Q

The _____ function takes a type as an argument, allocates enough memory to fit a value of that type,and returns a pointer to it.

A

new

33
Q

We can access fields of a struct using the ____ operator

A

.

34
Q

Embedded types in Go are an implementation of inheritance. True or false?

A

True

35
Q

How are embedded types defined?

A

type struct { …fields }

36
Q

A _______ is a list of methods that a type must have in order to implement the inter‐face.

A

method set

37
Q

What is a struct?

A

A struct is a container which contains has-a/is-a relationships.

38
Q

What is an interface?

A

An interface is a container which defines a bunch of methods which can be called.

39
Q

How are structs and interfaces related to each other?

A

If a struct is said to implement an interface, then the struct implements all the methods that the interface defines.

40
Q

To search for a smaller string in a bigger string, use the ____ function

A

strings.Contains

41
Q

To count the number of times a smaller string occurs in a bigger string, use the ______ function

A

strings.Count

42
Q

To determine if a bigger string starts with a smaller string, use the ______ function

A

strings.HasPrefix

43
Q

To determine if a bigger string ends with a smaller string, use the _____ function

A

strings.HasSuffix

44
Q

To find the position of a smaller string in a bigger string, use the _______ function

A

strings.Index

45
Q

To take a list of strings and join them together in a single string separated by anotherstring (e.g., a comma), use the __________ function

A

strings.Join

46
Q

To repeat a string, use the _________ function

A

strings.Repeat

47
Q

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

A

strings.Replace

48
Q

To split a string into a list of strings by a separating string (e.g., a comma), use the function

A

strings.Split

49
Q

To convert a string to all lowercase letters, use the function

A

strings.ToLower

50
Q

To convert a string to all uppercase letters, use the function

A

strings.ToUpper

51
Q

To convert a string to a slice of bytes use the _____ function

A

byte

52
Q

the io package has a ____ function that copies data from a Reader to a Writer

A

Copy

53
Q

To read or write to a []byte or a string, you can use the ______ struct found in the ______ package:

A

Buffer, bytes

54
Q

You can convert a Buffer into a []byte by calling ________

A

Buffer.Bytes()

55
Q

To open a file in Go, use the _____ function from the __ package

A

Open, os

56
Q

The _____ function from the ____ package serves as a shortcut to opening files using os.Open

A

ioutil.ReadFile

57
Q

To create a file, use the _________ function.

A

os.Create

58
Q

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

A

Readdir

59
Q

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.

A

os.Walk, path of the file, info of the file and err

60
Q

We can create our own errors by using the _____ function in the _____ package

A

New, errors

61
Q

The _____ package contains functions for sorting arbitrary data.

A

Sort

62
Q

The non-cryptographic hash functions can be found underneath the ____ package

A

hash

63
Q

The cryptographic hash functions can be found underneath the ____ package

A

crypto

64
Q

In Go, we can create a TCP server using the ____ package’s _____ function

A

net, Listen

65
Q

The ____ package allows us to parse arguments and flags sent to our program.

A

flag

66
Q

To create a goroutine, we use the keyword ____ followed by a _________

A

go, function invocation