I just got confused in the term Scanf return value in go lang

LIke Scanf function of fmt package return 2 value 1. Count and Other is error. But I am not clear about this and their use cases.

This is a good reason to look at the Golang docs. fmt.Scanf is declared as

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

So a simple program would look like this:

// This is adapted from the fmt.Sscanf example.
// Let's suppose that os.Stdin looks something like:
// "Kim is 22 years old"
package main

import (

func main() {
	var name string
	var age int
	n, err := fmt.Scanf("%s is %d years old", &name, &age)
	if err != nil {
        // wrong number of args or unexpected type
	fmt.Printf("%d: %s, %d\n", n, name, age)


With the input of “Kim is 22 years old”, we’d get an output something like

2: Kim, 22