N
N
Nelzz2021-04-08 12:43:53
go
Nelzz, 2021-04-08 12:43:53

Why is it returning a letter?

There is a code

package main

import "fmt"

func main() {
  i := 65
  fmt.Println(string(i))
}


why does the code return A?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2021-04-08
@Nelzz

Because 65 is the code for the English letter "A".
If you want to display 65, you need to use either the strconv or fmt module.

package main

import "fmt"
import "strconv"

func main() {
  var i int64 = 65
  fmt.Println(strconv.FormatInt(i, 10))
  // или так
  fmt.Printf("%d\n", i)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question