Data Types
In the Go programming language, a "type" refers to the category of value that a variable or expression can hold. Some examples of built-in types in Go include:
int: a signed integer type, capable of holding values from -2^63 to 2^63-1float64: a 64-bit floating-point type, capable of representing decimal values with a high degree of precisionstring: a sequence of Unicode charactersbool: a Boolean type that can hold the valuestrueorfalse
You can also create your own custom types by using the type keyword. Here's an example of creating a custom type "Myint" which is an int type
type MyInt intHere's an example of creating a struct type person which has three fields name, age, and address
type person struct {
name string
age int
address string
}You can also create a custom type by using the alias keyword. Here's an example of creating a custom type "MyString" which is an alias of the string type.
type MyString = stringYou can use these types just like the built-in types. For example, you can create a variable of type MyInt and assign it a value:
var myAge MyInt = 30
Last updated