English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In programming languages, identifiers are used to identify purposes. In other words, identifiers are user-defined names for program components. In Go, identifiers can be variable names, function names, constants, statement labels, package names, or types.
Example:
package main import "fmt" func main() { var name = "w3codebox" }
In the above example, there are three identifiers:
main:Package names
main:Function names
name:Variable names
Rules for defining identifiers:There are some valid rules for defining Go identifiers. These rules should be followed; otherwise, we will get a compile-time error.
The name of an identifier must start with a letter or an underscore (_), and may contain the letter "a-z" or "A-Z" or the digit 0-9as well as the character " _".
Identifier names cannot start with a number.
Identifier names are case-sensitive.
Keywords cannot be used as identifier names.
The length of an identifier name is not limited, but it is recommended to use only4to15the best length for a letter.
Example:
// Valid identifiers: _geeks23 geeks gek23sd Geeks geeKs geeks_geeks // Invalid identifiers: 212geeks if default
Note:
In Go, there are some predefined identifiers that can be used for constants, types, and functions. These names are not reserved, and you can use them in declarations. Here is a list of predefined identifiers:
Constants: true, false, iota, nil Type: int, int8, int,16, int,32, int,64, uint, uint,8, uint,16, uint,32, uint,64, uintptr, float32, float64, complex128, complex64, bool, byte, rune, string, error Function: make, len, cap, new, append, copy, close, delete, complex, real, imag, panic, recover
An identifier represented by the underscore character (_) is called a blank identifier. It is used as an anonymous placeholder rather than a regular identifier and has special meaning in declarations, operands, and assignments.
Identifiers that are allowed to be accessed from another package are called exported identifiers. Exported identifiers are those that meet the following conditions:
The first character of the name of an exported identifier should be a Unicode uppercase letter.
Identifiers should be declared in a package block, or they can be variable names or method names.
The uniqueness of an identifier means that it is unique among the set of identifiers available in a program or package and will not be exported.