An example of a struct in Go

This is an example Go program showing a struct.

package main

import (
        "fmt"
)

type T struct {
        name string
        value int
}

func main() {
        var puppy T
        puppy.name = "Pinky"
        puppy.value = 100;
        fmt.Println(puppy)
}

(download)

The output of the example looks like this:

{Pinky 100}


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer