Printing predefined errors

Report a typo

An interesting detail is that the fmt.Scan family of functions return the number of successfully scanned items n, and a predefined error err:

func Scan(a ...any) (n int, err error)
func Scanf(format string, a ...any) (n int, err error)
func Scanln(a ...any) (n int, err error)

Your task is to create a very simple Go program that handles and prints the predefined error err of the fmt.Scan() function when trying to read a string into the num variable of theint type.

Write a program in Go
package main

import "fmt"

func main() {
var num int

_, err := fmt.Scan(&num)
if err != nil {
fmt.Println(?)
return
}
}
___

Create a free account to access the full topic