Go Variable Name

Introduction

Go variable names must follow the following rules:

  • A variable name must begin with a letter.
  • A variable name cannot start with a number.
  • A variable name cannot contain spaces.
  • Go variable names are case-sensitive

If a variable's name starts with a lower-case letter, it can only be accessed within the current package.

The variable is considered as unexported variables.

If a variable's name begins with a capital letter, it can be accessed from outside packages.

The variable is considered as exported variables.

If you declare a variable without assigning it a value, Go will assign a default value to it.

package main //from w  w w  . jav  a2s  .com

import "fmt"
func main() {
  var quantity float32
  fmt.Println(quantity)

  var price int16
  fmt.Println(price)

  var product string
  fmt.Println(product)

}



PreviousNext

Related