Friday 3 May 2019

Go language: Read data from console or user


‘fmt.Scanln’ function is used to read data from user.

Syntax
fmt.Scanln(&variableName)

HelloWorld.go
package main

import "fmt"

func main() {

 var name string
 var id int

 fmt.Println("Enter your name")
 fmt.Scanln(&name)

 fmt.Println("Enter your id")
 fmt.Scanln(&id)

 fmt.Println("name : ", name, " id ", id)
}

Output
Enter your name
Krishna
Enter your id
123
name :  Krishna  id  123


Previous                                                 Next                                                 Home

No comments:

Post a Comment