Basic Data Types

Basic Data Types in Go #

Data type is an important concept in programming. It specifies the size and type of variable values.

Go is a statically typed language, meaning that once a variable type is defined, it can only store data of that type.

Three Basic Data Types in Go #

  1. bool: Represents a boolean value, which can be either true or false.
  2. Numeric: Represents integer types, floating point values, and complex types.
  3. string: Represents a sequence of characters (text).

Example #

This example demonstrates the use of 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!

Understanding basic data types is essential for working efficiently with variables, performing calculations, and controlling program flow in Go.