int64<\/td> 64 bits\/8 byte<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\nint<\/strong><\/p>\n\n\n\nSize: <\/strong>Platform Dependent.<\/p>\n\n\n\nOn 32 bit machines, the size of int will be 32 bits or 4 byte.<\/li> On 64 bit machines, the size of int will be 64 bits or 8 byte<\/li><\/ul>\n\n\n\nRange<\/strong>: Again Platform dependent<\/p>\n\n\n\nOn 32 bit machines, the size of int will be 32 bits or 4 bytes.<\/li> On 64 bit machines, the size of int will be 64 bits or 8 bytes<\/li><\/ul>\n\n\n\nWhen to Use:<\/strong><\/p>\n\n\n\nIt is a good idea to use int whenever using signed Integer other than the cases mentioned belowWhen the machine is a 32 bit and the range needed is greater than -231 to 231 -1, then use int64 instead of int. Note that in this case for int64, 2 32-bit memory addresses to form a 64-bit number together.<\/li> When the range is less then use the appropriate integer type.<\/li><\/ul><\/li><\/ul>\n\n\n\nProperties:<\/strong><\/p>\n\n\n\nDeclare a int<\/li><\/ul>\n\n\n\nvar a int<\/code><\/pre>\n\n\n\nint is default type for integer. <\/strong>When you don’t specify a type the default will be int<\/li><\/ul>\n\n\n\nb := 2 \/\/The default is also intfmt.Println(reflect.TypeOf(b)) => int<\/code><\/pre>\n\n\n\nbits <\/strong>package of golang can help know the size of an int <\/strong>on your system<\/li><\/ul>\n\n\n\n\/\/This is computed as const uintSize = 32 << (^uint(0) >> 32 & 1) \/\/ 32 or 64sizeOfIntInBits := bits.UintSizefmt.Println(sizeOfIntInBits) => 32 0r 34<\/code><\/pre>\n\n\n\nunsafe.Sizeof() <\/strong>function can also be used to see the size of int in bytes<\/li><\/ul>\n\n\n\nFull Working Code<\/strong><\/p>\n\n\n\nBelow is the full working code of the above properties<\/p>\n\n\n\n
package main\n\nimport (\n \"fmt\"\n \"math\/bits\"\n \"reflect\"\n \"unsafe\"\n)\n\nfunc main() {\n \/\/This is computed as const uintSize = 32 << (^uint(0) >> 32 & 1) \/\/ 32 or 64\n sizeOfIntInBits := bits.UintSize\n fmt.Printf(\"%d bits\\n\", sizeOfIntInBits)\n \n var a int\n fmt.Printf(\"%d bytes\\n\", unsafe.Sizeof(a))\n fmt.Printf(\"a's type is %s\\n\", reflect.TypeOf(a))\n \n b := 2\n fmt.Printf(\"b's typs is %s\\n\", reflect.TypeOf(b))\n}<\/code><\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\n64 bits\n8 bytes\na's type is int\nb's typs is int<\/code><\/pre>\n\n\n\nint8<\/strong><\/p>\n\n\n\nSize: <\/strong>8 bits or 1 byte<\/p>\n\n\n\nRange<\/strong>: -27<\/sup> to 27<\/sup> -1.<\/p>\n\n\n\nWhen to Use:<\/strong><\/p>\n\n\n\nUse int8 when there it is known that the int range will be between -27<\/sup> to 27<\/sup> -1. For temporary values such as loop invariants, it is still advisable to use int even though it might take more space because it is likely to be promoted to int in some operations or library calls.<\/li><\/ul>\n\n\n\nFor array values which lies between -27 to 27 -1, is a good use case for using int8. For eg if you are storing ASCII index for lowercase letters then int8 can be used.<\/li> It is a good idea to use int8 for data values.<\/li><\/ul>\n\n\n\nint16<\/strong><\/p>\n\n\n\nSize: <\/strong>16 bits or 2 byteRange<\/strong>: -215<\/sup> to 215<\/sup> -1.When to Use:<\/strong><\/p>\n\n\n\nUse int16 when there it is known that the int range will be between -215<\/sup> to 215<\/sup> -1. For temporary values such as loop invariants, it is still advisable to use int even though it might take more space because it is likely to be promoted to int in some operations or library calls.<\/li><\/ul>\n\n\n\nFor array values which lie between -215 to 215 -1, is a good use case for using int8. For eg if you are storing ASCII index for lowercase letters then int16 can be used.<\/li><\/ul>\n\n\n\nint32<\/strong><\/p>\n\n\n\nSize: <\/strong>32 bits or 4 byteRange<\/strong>: -231<\/sup> to 231<\/sup> -1.<\/p>\n\n\n\nint64<\/strong><\/p>\n\n\n\nSize: <\/strong>64 bits or 8 byteRange<\/strong>: -263<\/sup> to 263<\/sup> -1.When to Use:<\/strong><\/p>\n\n\n\nint64<\/strong> is used when range is higher. For eg time.Duration<\/strong> is of type int64<\/strong><\/li><\/ul>\n\n\n\n<\/span>UnSigned<\/strong><\/span><\/h3>\n\n\n\nUnSigned integers are of 5 types as below<\/p>\n\n\n\nType<\/strong><\/td>Size<\/strong><\/td><\/tr>uint<\/td> Platform Dependent<\/td><\/tr> uint8<\/td> 8 bits\/1 byte<\/td><\/tr> uint16<\/td> 16 bits\/2 byte<\/td><\/tr> uint32<\/td> 32 bits\/4 byte<\/td><\/tr> uint64<\/td> 64 bits\/8 byte<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\nuint<\/strong><\/p>\n\n\n\nSize: <\/strong>Platform Dependent.<\/p>\n\n\n\nOn 32 bit machines the size of int will be 32 bits or 4 byte.<\/li> On 64 bit machines the size of int will be 64 bits or 8 byte<\/li><\/ul>\n\n\n\nRange<\/strong>: Again Platform dependent<\/p>\n\n\n\nOn 32 bit machines the range of int will be -231<\/sup> to 231<\/sup> -1.<\/li>On 64 bit machines the range of int will be -263<\/sup> to 263<\/sup> -1<\/li><\/ul>\n\n\n\nWhen to Use:<\/strong><\/p>\n\n\n\nIt is a good idea to use uint whenever using signed Integer other than the cases mention belowWhen machine is a 32 bit and range needed is greater than -231<\/sup> to 231<\/sup> -1, then use int64<\/strong> instead int<\/strong>. Note that in this case for int64, 2 32-bit memory addresses to form a 64-bit number together.<\/li>When the range is less then use the appropriate int type<\/li><\/ul><\/li><\/ul>\n\n\n\nProperties:<\/strong><\/p>\n\n\n\nDeclare a uint<\/li><\/ul>\n\n\n\nvar a uint<\/code><\/pre>\n\n\n\nbits <\/strong>package of golang can help know the size of an uint <\/strong>on your system<\/li><\/ul>\n\n\n\n\/\/This is computed as const uintSize = 32 << (^uint(0) >> 32 & 1) \/\/ 32 or 64sizeOfUintInBits := bits.UintSizefmt.Println(sizeOfIntInBits) => 32 or 64<\/code><\/pre>\n\n\n\nunsafe.Sizeof() <\/strong>function can also be used to see the size of uint in bytes<\/li><\/ul>\n\n\n\nFull Working Code <\/strong><\/p>\n\n\n\nBelow is the full working code of the above properties<\/p>\n\n\n\n
package main\n\nimport (\n \"fmt\"\n \"math\/bits\"\n \"reflect\"\n \"unsafe\"\n)\n\nfunc main() {\n \/\/This is computed as const uintSize = 32 << (^uuint(0) >> 32 & 1) \/\/ 32 or 64\n sizeOfuintInBits := bits.UintSize\n fmt.Printf(\"%d bits\\n\", sizeOfuintInBits)\n\n var a uint\n fmt.Printf(\"%d bytes\\n\", unsafe.Sizeof(a))\n fmt.Printf(\"a's type is %s\\n\", reflect.TypeOf(a))\n}<\/code><\/pre>\n\n\n\nOutput:<\/strong><\/p>\n\n\n\n64 bits\n8 bytes\na's type is uint<\/code><\/pre>\n\n\n\nuintptr<\/strong><\/p>\n\n\n\nThis is an unsigned integer type that is large enough to hold any pointer address. Therefore is size and range are platform dependent.<\/p>\n\n\n\n
Size: <\/strong>Platform Dependent<\/p>\n\n\n\n