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 valuestrue
orfalse
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
Here's an example of creating a struct type person
which has three fields name, age, and address
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.
You 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:
Last updated