GO Program to print and declare variables

How to display different types of variables

Here we are explaining how to display different types of variables in Go program. We can use the built-in function fmt.println() to print anything. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.


How to display and declare different types of variables in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to print and declare different types of variables in the Go language. Here variables s,c is a string variable and x,y,b is an integer variable and a is a boolean variable. Given below are the steps which are used in the Go program. 


STEP 1: Import the package fmt

STEP 2: Start function main()

STEP 3: Initialise string variable s with value "first" and print using fmt.println()

STEP 4: Initialise integer variable x,y with values "5,7" and print using fmt.println()

STEP 5: Initialise boolean variable a with value "true" and print using fmt.println()

STEP 6: Declare integer variable and print using fmt.println()

STEP 7: Initialise string variable c with value "second" and print using fmt.println()

GO Source Code

                                          package main
import "fmt"

func main() {
    var s = "first"

    var x, y int = 5, 7
    fmt.Println(x, y)

    var a = true

    var b int

    c:= "second"


5 7