Google News
logo
Golang - Interview Questions
What do you understand by the scope of variables in Go?
The variable scope is defined as the part of the program where the variable can be accessed. Every variable is statically scoped (meaning a variable scope can be identified at compile time) in Go which means that the scope is declared at the time of compilation itself. There are two scopes in Go, they are:
 
Local variables : These are declared inside a function or a block and is accessible only within these entities.

Global variables : These are declared outside function or block and is accessible by the whole source file.
Advertisement