Data Types in Go
GOLang Data Types
Data types are one of the key things one has to know about while learning a language. They constitute the base of any programming language. I will be covering major data types that any programmer would be using throughout the day while working with GO.
Without wasting enough time lets start with GO data types.
Basic Types
- int
- float32
- float64
- bool
- strings
- derived types
Int
Ints are used to store 32 or 64 bits integer values defined in GO as follows:
The latter syntax is used when we want GO Compiler to pick the data type by inferring the value stored in the variable.
Floats
Floats are used to store decimal values in Go. Floats can be of two types
- float32
- float64
These two types correspond to the amount of space 32 bytes and 64 bytes respectively to store the numeric values.
floats can be created in Go using the following syntax:
Bool
Bool data type is used to store the boolean i.e true/false values in GO.
The following syntax can be used to create the booleans in Go
Strings
Strings are data types used to store non-numeric values like names, address, positions, etc.
GO. Strings in Go are immutable types, which means that strings once created can not be changed. This doesn't mean you can not alter the value of a string, instead every time you alter the value fo string a new string is created.
Derived Types
GO has vast varieties of derived types like
- Arrays
- Slices
- Structs
- Interfaces
- Maps
which I will be talking about in the next blog.
Here is a shortcode for data types covered in this blog
If you have a problem understanding this code, go through my previous blog on getting started with go.
Stay tuned for the next blog.
Happy Learning...
Comments
Post a Comment