Exported fields

Report a typo

Below are two Go code snippets. The first one is a file element.go, which is part of the chemistry package and contains the Element struct:

// chemistry/element.go
package chemistry

type Element struct {
    Name         string
    Symbol       string
    atomicNumber int
    meltingPoint float64
    Density      float64
}

The second one below is the main.go file, which imports the chemistry package. Fill in the blanks to correctly declare the hydrogen variable of the Element type and access its exported fields from the main package.

Fill in the gaps with the relevant elements
// main.go
package main

import (
    "fmt"
    "chemistry"
)

func main() {
    hydrogen := chemistry.{
        : "Hydrogen",
        : 0.08988,
        : "H",
    }
    fmt.Println("Element:", hydrogen)
}
ElementatomicNumberSymbolNameDensitymeltingPoint

Create a free account to access the full topic