Code
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type Weekend int | |
| const ( | |
| Sunday Weekend = iota | |
| Monday | |
| Tuesday | |
| Wednesday | |
| Thursday | |
| Friday | |
| Saturday | |
| ) | |
| func main() { | |
| fmt.Printf("%d",Saturday) | |
| } |
Iota-generator:
Things that confuse you Sunday Weekend = iota & Monday without value. Before we start Iota-generator first we understand monday without type or value
const (
c = 1 // c : 1
d // d : 1
)
fmt.Println(c,d)
This is only possible for consts. If you have 2 const and both have same type and same value then you omit next type or value. That's why program execute without error. Result of this problem is "11".
Now time to dive in iota generator. When you assign any const iota which means const initialize with 0, but after iota value increment. That's little different from previous code. As you know enumerate counts. That's iota do for us. Now you know the output of above code.
No comments:
Post a Comment