In this tutorial you will learn about the Go Variables and its application with practical example.
Go Variables
Variables are used to represent reserved memory locations that is used to store values, when we create a variable we are a suppose to allocate some memory space for that variable. Go is a statically typed programming language. This means that variables always have a specific type associated with it and that cannot be change. Data type for a variable specifies following-
- The amount of memory space allocated for variables.
- A data type specifies the possible values for variables.
- The operations that can be performed on variables.
Syntax :-
Below is syntax to declare a variable in GoLang –
1 |
var <name> <type> |
or
1 |
var <name> <type> = <expression> |
Example :-
1 2 3 4 5 6 7 8 |
package main import "fmt" func main(){ var hello_str string hello_str="Hello, World!" fmt.Println(hello_str) } |
Output :-