0
0
Goprogramming~20 mins

Basic data types in Go - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Go Basic Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
What is the output of this Go code snippet?

Consider the following Go program. What will it print when run?

Go
package main
import "fmt"
func main() {
    var a int = 5
    var b float64 = 3.2
    var c bool = true
    fmt.Println(a, b, c)
}
A5 3.2 true
B5 3 true
C5 3.2 1
D5 3.2 false
Attempts:
2 left
๐Ÿ’ก Hint

Remember that fmt.Println prints values separated by spaces and booleans print as true or false.

โ“ Predict Output
intermediate
2:00remaining
What is the output of this Go code with type conversion?

What does this Go program print?

Go
package main
import "fmt"
func main() {
    var x int = 10
    var y float64 = float64(x) / 4
    fmt.Printf("%.2f", y)
}
A2.00
B2.5
C2.50
D2
Attempts:
2 left
๐Ÿ’ก Hint

Look at the Printf format specifier and the type conversion.

๐Ÿ”ง Debug
advanced
2:00remaining
What error does this Go code produce?

What error will this Go program cause when compiled?

Go
package main
func main() {
    var a int = "hello"
    println(a)
}
Aundefined: a
Bcannot use "hello" (type string) as type int in assignment
Cmissing return statement
Dsyntax error: unexpected string literal
Attempts:
2 left
๐Ÿ’ก Hint

Check the variable type and the assigned value type.

๐Ÿง  Conceptual
advanced
2:00remaining
How many bytes does a Go int use on a 64-bit system?

On a 64-bit system, how many bytes does the int type occupy in Go?

A16 bytes
BDepends on the compiler
C4 bytes
D8 bytes
Attempts:
2 left
๐Ÿ’ก Hint

Think about the system architecture and Go's default int size.

๐Ÿš€ Application
expert
2:00remaining
What is the value of variable 'result' after running this Go code?

Given the code below, what is the value of result after execution?

Go
package main
func main() {
    var a uint8 = 250
    var b uint8 = 10
    var result uint8 = a + b
    println(result)
}
A4
Boverflow error
C260
D250
Attempts:
2 left
๐Ÿ’ก Hint

Remember that uint8 can only hold values from 0 to 255 and wraps around on overflow.