Go Language basic type (1)

Source: Internet
Author: User

  • Variable
  • Use the keyword var to define the variable and automatically initialize it to a value of 0. If you provide an initialization value, you can omit the variable type, which is automatically inferred by the compiler.
  • You can define a variable inside a function by using the : = method
  • Func Main () {x:}
  • Multiple variables can be defined at once
  • " ABC ", 123var (a intb float32) func main () {n, S:"Hello, world! " println (x, S, N)}
  • _ is used to ignore the value, the placeholder.

  • The compiler uses unused local variables as errors
  • Constant
  • The constant value must be a number, string, and Boolean value that can be determined by the compilation period.
  • const x, y int = 1, 2//"Hello, world! " ////= ten,= false"xxx" // No compilation errors are raised with local constants. }
  • In a constant group, if the type and initialization values are not provided, it is treated the same as the previous constant.
  • The constant value can also be Len, cap, unsafe. The function return value of the result can be determined by the compile period such as Sizeof
  • Enumeration
  • The IOTA keyword defines the self-increment enumeration value in a constant group that starts at 0 by the row count.
  • = Iota////1//2//3//4//5//6)
  • If Iota is interrupted, it must be explicitly restored.
  • = Iota////1"C" // CD       //= Iota//4  //5)
  • Basic type

Go Language basic type (1)

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.