Go Data Types

Gayathri. B

 Go Data Types

In programming, a data type defines the kind of data a variable can hold, including its size and how it's stored in memory.
Go is a statically typed language, which means each variable must be assigned a specific type, and that type cannot change.

Go supports three primary categories of data types:

  • bool: Represents a boolean value (true or false)
  • Numeric: Includes integers, floating-point numbers, and complex numbers
  • string: Represents a sequence of characters

Example:

 Using Different Data Types in Go
package main
import ("fmt")
func main() {
  var a bool = true       // Boolean
  var b int = 5           // Integer
  var c float32 = 3.14    // Floating-point number
  var d string = "Hi!"    // String
  fmt.Println("Boolean:", a)
  fmt.Println("Integer:", b)
  fmt.Println("Float:  ", c)
  fmt.Println("String: ", d)
}

Output:

Boolean: true
Integer: 5
Float:   3.14
String:  Hi!

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send