Go fast-04-constants, operators and pointers

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

Directory

      • Constant operators and pointers
        • Constant
          • Defined
          • Iota
        • Operator
        • Pointer

Summary

Define constants, constant groups, upstream expressions, iota,++/–, pointers

constants, operators and pointers

Constant

Defined

    • Constants const are defined using keywords
    • The value of the constant is determined at compile time, so the runtime cannot change
    • A function in a constant expression must be a built-in function (because the return value of a function you write is determined at run time)

Example

const (    "text"len(text))

Use the value of the upstream expression in a constant group if you do not specify a default value

const (    a = 1   //常量必须有值,所以a必须指定值    b    c)fmt.Println(a, b, c)    //1 1 1

Iota

    • Iota is a counter in a constant group, starting with 0, the value of iota is automatically incremented by 1 for each constant defined in a constant group.
    • Each time a new constant group is defined, the iota will be zeroed
const (    "D"    e    iota    g)const (    iota//D D 2 3fmt.Println(k)          //0

Operator

++,--Only as a statement, that is, a single line of++

a := 1a++fmt.Println(a)var//error

Pointer

    • Using the "." Direct manipulation pointer
    • Use the "&" to take a variable address
    • Use "*" to access objects indirectly through pointers
    • Pointer default value is nil NOT NULL
    • Type cannot be omitted when defining pointers
a := 1var pa *int = &afmt.Println(pa)  //0xc0820062e0//1var pb *int//nil

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.