0
0
Goprogramming~15 mins

Zero values in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Zero Values in Go
๐Ÿ“– Scenario: Imagine you are creating a simple program to track basic information about a product in a store. You want to understand how Go automatically sets default values for variables when you don't assign them explicitly.
๐ŸŽฏ Goal: You will create variables of different types without assigning values and observe their zero values in Go.
๐Ÿ“‹ What You'll Learn
Create variables of type int, float64, bool, and string without assigning values.
Create a variable of type int and assign it a value.
Print all variables to see their zero values or assigned values.
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Understanding zero values helps you avoid bugs when variables are not initialized explicitly in Go programs.
๐Ÿ’ผ Career
Many Go jobs require knowledge of zero values to write clean, bug-free code and understand default behaviors.
Progress0 / 4 steps
1
Create variables without assigning values
Create variables called count of type int, price of type float64, available of type bool, and name of type string without assigning any values.
Go
Need a hint?

Use the var keyword followed by the variable name and type, but do not assign any value.

2
Assign a value to one variable
Add a variable called count of type int and assign it the value 10. Keep the other variables price, available, and name declared without values.
Go
Need a hint?

Assign the value 10 to count using = after the type.

3
Print all variables to see their values
Use fmt.Println to print the variables count, price, available, and name in the main function. Import the fmt package at the top.
Go
Need a hint?

Use fmt.Println for each variable to print its value on a new line.

4
Run the program and observe the output
Run the program and observe the output. It should print the value 10 for count and zero values for price, available, and name. Write a print statement for each variable as shown.
Go
Need a hint?

The output shows the assigned value for count and zero values for the other variables.