Lesson Five Golang language variables

Source: Internet
Author: User

1 variables three kinds of declaration: ( the first kind of Var and type are redundant;

the second is the most concise, but the second can only be used in a function, not the declaration of a global variable.

The first type:

var v_name V_type ( note order = value
" FMT " Func Main () {    varint    123     Fmt. Println (vname1)    FMT. Println (vname2)    FMT. Println (Vname3)}

Second type: (initialization declaration)

If you are in the same code block, we cannot use the initialization declaration again for variables of the same name

var= value ( self-derived type )
" FMT " Func Main () {    var789    FMT. Println (v1)    FMT. Println (v2)    FMT. Println (v3)}

The third type:

: = Value (: = The variable on the left must be not declared )

2 value types and reference types

All basic types, such as int, float, bool, and string, are value types, using variables of these types to point directly to a value that exists in memory, and when an equal sign is used to = assign the value of a variable to another variable, such as: j = i , the value of I is actually copied in memory

&i to get the memory address of the variable I, for example: 0xf840000040 (each time the address may be different). The value of a variable of value type is stored in the stack.


Lesson Five Golang language variables

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.