English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Keywords or reserved words are words used in a language for certain internal processes or to represent certain predefined actions. Therefore, these words are not allowed to be used as identifiers. This will cause compilation errors.
//Go Program to Explain //Use the keyword package main import "fmt" // Here, package, import, func, // var is a keyword func main() { // Here, a is a valid identifier var a = "w3codebox" fmt.Println(a) //Here, the default is set to a //Illegal identifiers and //The compiler will throw an error // var default = "GFG" }
Output:
w3codebox
in Go LanguageThere are25keywordsas shown below:
break | case | chan | const | continue |
default | defer | else | fallthrough | for |
func | go | goto | if | import |
interface | map | package | range | return |
select | struct | switch | type | var |
//Go Program Example //Use the keyword //Here, the package keyword is used for //Include the main package in the program package main // The import keyword is used to //Import "fmt" into your package import "fmt" // func is used for //Create a function func main() { //Here, the var keyword is used to create variables //Pname, Lname, and Cname are valid identifiers var Pname = "oldtoolbag.com" var Lname = "Go Language" var Cname = "Keyword" fmt.Printf("Site Domain: %s", Pname) fmt.Printf("\nLanguage Name: %s", Lname) fmt.Printf("\nChapter Name: %s", Cname) }
Output:
Site Domain: oldtoolbag.com Language Name: Go Language Chapter Name: Keyword