Back to questions
JuniorTheoryCommon
What does the program print?
package main
import "fmt"
func main() {
s := "ёж"
fmt.Println(s[0], len(s))
}209 4
- Expecting
ёor its code 1105:s[0]is onebyte, a number from 0 to 255, here the first of the two bytes ofё. - Expecting
2forlen(s):lencounts bytes, not letters, and each Cyrillic letter takes two bytes in UTF-8.
- Why does
for i, r := range sgive different indices thans[i]on UTF-8 text? - What is the difference between a
byteand arunein Go?