Data Types in Go language

Data type defines a set of related values, describe the operations that can be done on them and define the way the stored in memory. 
For example: Suppose you have a Car of VW Polo, but a car can be of any other company with some other basic and some advanced features.
But if we called a name Car, then in your mind a picture is created that there is a vehicle with 4-wheels and steering. Each car has some features like the color, company, make, model etc.

Types in programming work in a similar way, For example, "Hello World" is a string and every string have some length.


Go Comes with different types to represent numbers, Numbers can be categorized into two broad categories...


The integer represents only those numbers which don't include any decimal places and can be of any positive and negative numbers.
Example : {1, 3, -4, 11, 123, 534} all are integer numbers

Go's integer type can be uint8, uint16, uint32, uint64, int8, int16, int32, and int64. 8, 16, 32 and 64 represents the number of bits each of data type uses.

uint means "Unsigned integer" which only includes positive integers, whereas int means "signed integers" which includes positive and negative both numbers.
Following table represents unsigned integral data types along with their allowed range.

Data Type Memory Used Range
uint8 8 bits 0 to 28-1 (0 to 255)
uint16 16 bits 0 to 216-1 (0 to 65535)
uint32 32 bits 0 to 232-1 (0 to 4294967295)
uint64 64 bits 0 to 264-1

Following table represents integral (signed) data types along with their allowed range.

Data Type Memory Used Range
uint8 8 bits -27 to 27-1 (-128 to 127)
uint16 16 bits -215-1 to 215-1 (-32768 to 32767)
uint32 32 bits -231-1 to 231-1 (-2147483648 to 2147483647)
uint64 64 bits -263-1 to 263-1

In Go int8, int32 are alias byte and rune respectively. Also there are 3 machine dependent data types uint, int, uintptr. They are machine dependent because their size depend on the machine architecture in which you program is running.


Popular posts from this blog

Program to calculate telephone bill

Sum of two numbers in go lang

Program to check a year is leap year or not.

String in golang


Arrays in C Language

Reserved Words in Java

Data types in Java

Pointers in C Language

Literals in Java