Câu hỏi phỏng vấn Golang
Câu hỏi

What is rune type in Go?

Câu trả lời

The rune type in Go is a data type used to represent Unicode characters. It is an alias for the int32 type, which means it can store an integer value of up to 32 bits. This capacity allows it to represent any Unicode code point, as Unicode characters are encoded in UTF-8 and can vary in length from 1 to 4 bytes[1][2].

In Go, unlike some other programming languages, there is no distinct character data type like char. Instead, Go uses the rune type to handle characters, especially when dealing with Unicode, making it a versatile tool for internationalization within applications[1][2][4]. Each rune value corresponds to a Unicode code point, which is a unique number assigned to each character in the Unicode standard[2].

When working with strings in Go, which are sequences of bytes, converting a string to a slice of runes is a common operation if one needs to process it character by character. This is particularly useful for strings containing non-ASCII characters where each character can be more than one byte long[1][2].

Here is an example of how to use runes in Go:

package main

import "fmt"

fun...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

How to compare two interfaces in Go?

junior

What are Goroutines?

middle

Have you worked with Go 2?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào