To create a variable of type string in Go, we use the var
keyword followed by the variable name and the value of the string. Here is an example:
main.go38 chars2 lines
In this example, we are declaring a variable named greeting
of type string and assigning it a value of "Hello, world!".
We can also declare a variable without specifying its value. In this case, Go initializes the variable with a default value, which is an empty string.
main.go19 chars2 lines
In this case, we are declaring a variable named message
of type string and not assigning any value to it.
gistlibby LogSnag