Open In App
Related Articles

Identifiers in Go Language

Improve Article
Save Article
Like Article

In programming languages, identifiers are used for identification purposes. In other words, identifiers are the user-defined names of the program components. In the Go language, an identifier can be a variable name, function name, constant, statement label, package name, or type. 


package main
import "fmt"

func main() {

 var name = "GeeksforGeeks"

There is a total of three identifiers available in the above example:

  • main: Name of the package
  • main: Name of the function
  • name: Name of the variable

Rules for Defining Identifiers: There are certain valid rules for defining a valid Go identifier. These rules should be followed, otherwise, we will get a compile-time error.

  • The name of the identifier must begin with a letter or an underscore(_). And the names may contain the letters ‘a-z’ or ’A-Z’ or digits 0-9 as well as the character ‘_’.
  • The name of the identifier should not start with a digit.
  • The name of the identifier is case-sensitive.
  • Keywords are not allowed to be used as an identifier name.
  • There is no limit on the length of the name of the identifier, but it is advisable to use an optimum length of 4 – 15 letters only.


// Valid identifiers:

// Invalid identifiers:


  • In the Go language, there are some predeclared identifiers available for constants, types, and functions. These names are not reserved, you are allowed to use them in the declaration. Following is the list of predeclared identifiers:
For Constants:
true, false, iota, nil

For Types:
int, int8, int16, int32, int64, uint,
uint8, uint16, uint32, uint64, uintptr,
float32, float64, complex128, complex64,
bool, byte, rune, string, error

For Functions:
make, len, cap, new, append, copy, close, 
delete, complex, real, imag, panic, recover
  • The identifier represented by the underscore character(_) is known as a blank identifier. It is used as an anonymous placeholder instead of a regular identifier, and it has a special meaning in declarations, as an operand, and in assignments.
  • The identifier which is allowed to access it from another package is known as the exported identifier. The exported identifiers are those identifiers which obey the following conditions:
    • The first character of the exported identifier’s name should be in the Unicode upper case letter.
    • The identifier should be declared in the package block or be a variable, function, type, or method name within that package.

In the below example, file1.go contains an exported variable called ExportedVariable, which is accessible within the same file. It also imports the file2 package and accesses the exported variable AnotherExportedVariable from file2.go. By running go run file1.go, it will print the value of ExportedVariable (“Hello, World!”) from file1.go and the value of AnotherExportedVariable (“Greetings from file2!”) from file2.go. This demonstrates the concept of exported identifiers being accessible from another package in Go.

Example of file2:


package file2
// Exported variable
var AnotherExportedVariable = "Greetings from file2!"

Example of file1:


// file1.go
package main
import (
// Exported variable
var ExportedVariable = "Hello, World!"
func main() {
    // Accessing exported identifier in the same file
    // Accessing exported identifier from another package


Hello, World!
Greetings from file2!
  • The uniqueness of the identifiers means the identifier is unique from the other set of the identifiers available in your program, or in the package and they are not exported.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 20 Sep, 2023
Like Article
Save Article
Similar Reads