Bird
Raised Fist0
Goprogramming~20 mins

Basic data types in Go - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. Which Go data type is used to store true or false values?
easy
A. float64
B. int
C. string
D. bool

Solution

  1. Step 1: Understand the data types

    In Go, bool is used for true/false values, int for whole numbers, string for text, and float64 for decimals.
  2. Step 2: Match the type to true/false

    Since true/false are boolean values, the correct type is bool.
  3. Final Answer:

    bool -> Option D
  4. Quick Check:

    Boolean type = bool [OK]
Hint: True/false values always use bool type in Go [OK]
Common Mistakes:
  • Choosing int for true/false
  • Using string for boolean values
  • Confusing float64 with bool
2. Which of the following is the correct way to declare an integer variable named age in Go?
easy
A. int age
B. var age int
C. age := int
D. var int age

Solution

  1. Step 1: Recall Go variable declaration syntax

    In Go, variables are declared with var followed by the name and then the type.
  2. Step 2: Check each option

    var age int matches this syntax: var age int. Others do not follow Go syntax.
  3. Final Answer:

    var age int -> Option B
  4. Quick Check:

    Variable declaration = var name type [OK]
Hint: Use 'var name type' to declare variables in Go [OK]
Common Mistakes:
  • Writing type before variable name
  • Using := without initialization
  • Mixing order of var and type
3. What will be the output of this Go code?
package main
import "fmt"
var x int = 10
var y float64 = 5.5
var z string = "Go"
func main() {
	fmt.Println(x, y, z)
}
medium
A. 10 5.5 Go
B. 10 5 Go
C. 10 5.5 "Go"
D. Error: cannot print variables

Solution

  1. Step 1: Understand variable values

    Variable x is 10 (int), y is 5.5 (float64), and z is "Go" (string).
  2. Step 2: Check fmt.Println output

    fmt.Println prints values separated by spaces without quotes for strings.
  3. Final Answer:

    10 5.5 Go -> Option A
  4. Quick Check:

    Print values as is, strings without quotes [OK]
Hint: fmt.Println prints strings without quotes by default [OK]
Common Mistakes:
  • Expecting quotes around strings
  • Confusing float64 with int
  • Thinking fmt.Println causes error
4. Find the error in this Go code snippet:
var name string = 123
fmt.Println(name)
medium
A. fmt.Println requires parentheses
B. Missing semicolon after declaration
C. Cannot assign int to string variable
D. Variable name is a reserved keyword

Solution

  1. Step 1: Check variable assignment types

    The variable name is declared as string but assigned the integer 123, which is a type mismatch.
  2. Step 2: Verify other syntax

    Semicolons are optional in Go, fmt.Println is correctly used, and name is not a reserved keyword.
  3. Final Answer:

    Cannot assign int to string variable -> Option C
  4. Quick Check:

    Type mismatch error = assigning int to string [OK]
Hint: Match variable type and assigned value type exactly [OK]
Common Mistakes:
  • Assigning wrong type value
  • Thinking semicolon is mandatory
  • Confusing reserved keywords
5. You want to store a person's age, height in meters, name, and if they are a student. Which Go variable declarations are correct?
hard
A. var age int var height float64 var name string var isStudent bool
B. var age float64 var height int var name bool var isStudent string
C. var age string var height string var name int var isStudent int
D. var age bool var height bool var name float64 var isStudent int

Solution

  1. Step 1: Match data types to real-world data

    Age is a whole number, so int. Height can have decimals, so float64. Name is text, so string. Student status is true/false, so bool.
  2. Step 2: Check each option

    var age int var height float64 var name string var isStudent bool matches these types correctly. Others assign wrong types to variables.
  3. Final Answer:

    var age int var height float64 var name string var isStudent bool -> Option A
  4. Quick Check:

    Correct types for data = int, float64, string, bool [OK]
Hint: Use int for whole numbers, float64 for decimals, string for text, bool for true/false [OK]
Common Mistakes:
  • Mixing int and float64
  • Using bool for text
  • Assigning string to boolean
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard