3.1 KiB
Which one is not a predeclared data type of Go?
- int
- float64
- uint64
- uint
- duration CORRECT
- int8
- rune
- byte
- float32
- complex128
What's a predeclared data type?
- A data type used only in the compiler
- A built-in data type that comes with Go that you can use it from anywhere without importing any package CORRECT
- The data type of a variable
By using only 8 bits, how many different numbers or states can you represent?
- 8
- 16
- 256 CORRECT
- 65536
3: 2^8 is 256, so you can represent 256 different states.
How many bits 2 bytes contains?
- 2
- 8
- 16 CORRECT
- 32
- 64
What's the output of the following code?
fmt.Printf("%08b = %d", 2, 2)
- 00000001 = 2
- 00000010 = 2 CORRECT
- 00000100 = 2
- 00001000 = 2
EXPLANATION = From right to left, each bit goes from 2^0 to 2^(n - 1).
1: EXPLANATION. Here: 1 is the first digit from the right. So, it is 2^(1 - 1) = 2^0 = 1.
2: EXPLANATION. Here: 1 is the second digit from the right. So, it is 2^(2 - 1) = 2^1 = 2.
3: EXPLANATION. Here: 1 is the third digit from the right. So, it is 2^(3 - 1) = 2^2 = 4.
4: EXPLANATION. Here: 1 is the fourth digit from the right. So, it is 2^(4 - 1) = 2^3 = 8.
How many bytes of memory does an int64 value use?
- 4
- 8 CORRECT
- 32
- 64
2: 1 byte is 8 bits and int64 is 64 bits. So, 64/8=8 bytes.
How many bytes are needed to store a value of uint32 type?
- 4 CORRECT
- 8
- 32
- 64
2: 1 byte is 8 bits and uint32 is 32 bits. So, 32/8=4 bytes.
What's the size of int data type?
- Depends: 32 bits or 64 bits. CORRECT
- 32 bits
- 64 bits
1: That's right. Go can change its size at the compile-time depending on which target machine you're compiling your program into.
English letters can be represented by the numbers within the range of: 0-255. For example, 'A' can be 65. Or, 'B' can be 66. So, what's the best data type for storing an English letter?
- byte CORRECT
- rune
- int64
- float64
1: That's right. A byte can represent 0-255 different values. So, it's a great fit for representing English letters, and numbers.
2: In practice, you can do it with a rune value. However, rune is 32-bits long and it can store almost every letter in existince. I'm asking for the optimal data type. Try again.
3: That would be too large for only 255 different numbers.
4: Float is not the best data type for numbers without fractional parts.
What does the following code print?
var letter uint8 = 255
fmt.Print(letter + 5)
- 0
- 4 CORRECT
- 5
- 260
2: Unsigned integers wrap around after their maximum capacity. Uint8's max is 255, so, if 255 + 1 is 0, then 255 + 5 is 4.
3: You're very close.
4: Uint8's max capacity is 255. It can't be 260.
What does the following code print?
var num int8 = -128
fmt.Print(num - 3)
- -131
- 125 CORRECT
- -125
1: int8's min capacity is -128. It can't be -131.
2: Signed integers wrap around after their minimum capacity. int8's min is -128, so, if -128 - 1 is 127, then -128 - 3 is 125.