Menu
Coddy logo textTech

Integers (int)

Part of the Fundamentals section of Coddy's GO journey — lesson 7 of 109.

Integers (int) are whole numbers without decimal points. Go uses int to store these values.

Let's create integer variable using the var keyword:

var age int = 25
fmt.Println("Age:", age)

After executing this code, you will see Age: 25 displayed on the screen. We've created an integer variable named age with the value 25.

Now, let's create an integer using Go's short declaration syntax with :=:

score := 95
fmt.Println("Score:", score)

After executing this code, you will see Score: 95 displayed on the screen. The := operator automatically determines that score should be an integer type based on the value 95.

challenge icon

Challenge

Beginner

In this challenge, you'll practice working with integer variables in Go.

Integers (int) are whole numbers without decimal points. They can be positive, negative, or zero.

Your tasks:

  • Create an integer variable named age with a value of 25
  • Create another integer variable named year with a value of 2023
  • Create a third integer variable named temperature with a value of -5
  • Print all three variables on separate lines using fmt.Println()

Cheat sheet

Integers (int) are whole numbers without decimal points. They can be positive, negative, or zero.

Create integer variables using the var keyword:

var age int = 25
fmt.Println("Age:", age)

Create integers using Go's short declaration syntax with :=:

score := 95
fmt.Println("Score:", score)

Try it yourself

package main

import "fmt"

func main() {
	// Create your integer variables here
	age := ?
	year := ?
	temperature := ?
	
	// Print the variables on separate lines
	fmt.Println(?)
	fmt.Println(?)
	fmt.Println(?)
	
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals