github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume1/section2/declarenumerics/declarenumerics.go (about)

     1  // Various examples to declare Go's numeric types.
     2  package main
     3  
     4  import "fmt"
     5  
     6  func main() {
     7  
     8  	// Declare a 32 bit integer without initializing it
     9  	// Remember: variables declared without an explicit initial value are given their zero value
    10  	var myInteger int32
    11  
    12  	// We expect to see a value of 0 since the zero-value of an int32 is 0
    13  	fmt.Println("Value of myInteger: ", myInteger)
    14  
    15  	// Declare and Initialize 2 float64's and then show their sum
    16  	var myFloatingPointNumber float64 = 36.333
    17  	var myOtherFloatingPointNumber float64 = 306.96969696
    18  	fmt.Println("Sum of my floating point numbers: ", myFloatingPointNumber+myOtherFloatingPointNumber)
    19  
    20  	// We can omit the type, Go will figure out what the type is
    21  	x, y, z := 0, 1, 2
    22  	fmt.Printf("x: %d\ty: %d\tz: %d\n", x, y, z)
    23  
    24  	// Example of a complex number
    25  	myComplexNumber := 5 + 24i
    26  	fmt.Println("Value of myComplexNumber: ", myComplexNumber)
    27  
    28  	// Example of grouping constant declaration/initializations
    29  	const (
    30  		speedOfLight     = 299792458 // unit: m/s
    31  		pi               = 3.14
    32  		myFavoriteNumber = 108
    33  	)
    34  
    35  	// Example of grouping variable declarations/initializations
    36  	var (
    37  		a int = 0        // an integer
    38  		b     = 1.8 + 3i // a complex number
    39  		c     = 2.7      // a floating-point number
    40  	)
    41  	fmt.Printf("a: %v\tb: %v\tc: %v\n", a, b, c)
    42  
    43  }