You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the indices rely on the current instruction set, it assumes that it is sequential when we break it down to just the primitive data types.
Example: We have a type A struct. type A struct { Name string Age int isMale bool Income float64 }
In the struct, Name is index 0, Age is index 1, isMale is index 2, Income is index 3.
Then in the case of array of structs, we can have: [5]A{}
This gives us the following indices:
[0] Name: 0
[0] Age: 1
[0] isMale: 2
[0] Income: 3
[1] Name: 4
[1] Age: 5
...
[4] Income: 19
This will work, if we initialise each struct in sequence, since we can piggyback from the previous index and increment it directly.
However, in the case of keyed initialisation, sequence is not guaranteed, we can initialise Age/isMale/Income first instead of Name. Then, this piggybacking of indices will not work anymore.