码迷,mamicode.com
首页 > 其他好文 > 详细

6.struct_types

时间:2018-03-17 00:36:02      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:imp   ogr   init   pre   span   initial   res   count   field   

Declare, create and initialize struct types

// Sample program to show how to declare and initialize struct types.

package main

import "fmt"

// example represents a type with different fields.
//示例表示具有不同字段的类型。

type example struct {
    flag    bool
    counter int16
    pi      float32
}

func main() {
    // Declare a variable of type example set to its
    // zero value.

    var e1 example

    //  display the value
    fmt.Printf("%+v\n", e1)

    // Declare a variable of type example and init using
    // a struct literal.

    e2 := example{
        flag:    true,
        counter: 11,
        pi:      3.14159,
    }
    // display the field values
    fmt.Println("flag", e2.flag)
    fmt.Println("counter", e2.counter)
    fmt.Println("pi", e2.pi)

    /*
        {flag:false counter:0 pi:0}
        flag true
        counter 11
        pi 3.14159
    */
}

6.struct_types

标签:imp   ogr   init   pre   span   initial   res   count   field   

原文地址:https://www.cnblogs.com/zrdpy/p/8586513.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!