Two forms of struct declaration in Go -


i've got 2 forms of struct declaration in function scope. far see bellow-listed snippet woks fine. question what's difference between 2 declaration ways? semantic question or there tricky under covers?

package main  import "fmt"  func main() {     type person1 struct {         name string         id int     }     person1 := &person1{name : "john smith", id : 10}     fmt.printf("(%s, %d)\n", person1.name, person1.id)     var person2 struct {         name string         id int     }     person2.name = "kenneth box"     person2.id = 20     fmt.printf("(%s, %d)\n", person2.name, person2.id) } 

one named type - can create multiple variables of type, if need to, using type name.

the other type has no name. cannot create more variables of type other using := operator.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -