Golang basic data types, constants, identifiers

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Basic data types, constants, identifiers

1. Identifiers, Keywords

 Break        default      func         Interface    Select Case         defer        Go           Map          structChan         Else         Goto          Package      SwitchConst        Fallthrough  if           Range        typeContinue      for          Import       return       var

2. Type

boolbytecomplex64complex128float32float64intint8int16int32int64runestringuintuint8uint16uint32uint64uintptr

3. Constants

true   false   iota

4, 0 value

nil

5. Functions

appendcapclosecomplexcopydeleteimaglenmakenewpanicprintprintlnrealrecover

6, _

The empty Identifier "_" is a placeholder that is used to assign a value to an empty marker symbol at the time of the assignment operation, thus achieving the purpose of discarding the value. The null identifier is not a new variable, so it is used for: = When you manipulate the symbol, you must assign at least one value to the other.

7. Constants and variable declarations

Constant declaration: const
Variable declaration: var (or: = Life and Assignment)

The go language automatically infers the type of the variable being declared, and go always assigns a value of zero to the variable that does not display the initialization.

Declaring a variable's data type is always behind the variable

Example:

const512           // 常量,其类型兼容任何数字constuint161421     // 常量,类型:uint161.5                 // 变量,推断类型 flat64varint                   // 变量,值为0,类型 intvarfalse           // 变量,推断类型 bool

8. Integer type and Boolean value

Type descriptionbyteEquivalent touint8intDepending on the implementation under different platforms, it can beInt32OrInt64int8     [ -128,127]Int16   [ -32768,32767]Int32   [ -2147483648,2147483647]Int64   [ -9223372036854775808,9223372036854775807]RuneEquivalent toUInt32UINTDepending on the implementation under different platforms, it can beUInt32OrUInt64uint8   [0,255]uint16  [0,65535]UInt32  [0,4294967295]UInt64  [0,18446744073709551615]UIntPtrAn unsigned integer that can fit the pointer value exactly (onBit platform isUInt32,onBit platform isUInt64In the C language we can see the byte length of the type through the sizeof operator, which can be used in the go language via the unsafe.sizeof function.

9. Floating-point type

类型  说明float32 ±3.402 823 466 385 288 598 117 041 834 845 169 254 40x10<sup>38</sup> 计算精度大概是小数点后7个十进制数float64 ±1.797 693 134 862 315 708 145 274 237 317 043 567 981x10<sup>38</sup> 计算精度大概是小数点后15个十进制数complex32   复数,实部和虚部都是float32complex64   复数,实部和虚部都是float64

10. Boolean type

truefalsetruefalse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.