Go Learning notes: variables

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

Go is a statically typed language, and variables are of a definite type. The compiler checks the correctness of the variable type in the function call.

Use var keywords to define variables.

The basic types of Go are:

    • bool

    • String

    • int int8 int16 int32 int64

    • UINT uint8 uint16 UInt32 UInt64 uintptr

    • BYTE//Uint8 Alias

    • Rune//Int32 aliases represent a Unicode code

    • float32 float64

    • Complex64 complex128

Look at the following example

Package Mainimport "FMT" Func Main () {//' var ' keyword is used to define one or more variables var a string = "initial" FMT. Println (a)//You can define multiple variables at once var b, c int = 1, 2 fmt. Println (b, c)//Go infers the type of the variable with the initial value var d = True FMT. When a variable is Println (d)//defined, a variable with no initial value is initialized by default to 0 value//integer 0 value is 0 var e int fmt. PRINTLN (E)//": =" syntax is a shortcut for defining and initializing variables f: = "short" FMT. Println (f)}

The output result is

Initial1 2true0short



Related Article

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.