Get the App
SLTechnology News&Howtos  ›  Development  › 

Can global and local variable names be the same in Go language?

Shulou Source: shulou.com Published: 2022-06-01 02:31:40 09月19日 Update

This article "Go language global variables and local variable names can be the same?" most people do not understand, so the editor summarized the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "Go language global variables and local variable names can be the same" article it.

Global and local variable names can be the same in Go language programs, but local variables within functions are preferred. Examples are as follows:

Package main

Import "fmt"

/ * declare global variables * /

Var g int = 20

Func main () {

/ * declare local variables * /

Var g int = 10

Fmt.Printf ("result: G =% d\ n", g)

}

The output of the above example is as follows:

Results: G = 10 or more is about the article "can global variables and local variables have the same name in Go language?". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Variables local global content same name language results examples articles knowledge articles values functions most that is more steps knowledge points programs Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information OPPO Reno MySQL MariaDB