This is a creation in Article, where the information may have evolved or changed.
Directory
-
- Constant operators and pointers
- Constant
- 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