golang中byte和rune的区别?

golang中byte和rune的区别?

runebyte在go语言中都是字符类型,从源码来看他们都是别名形式

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

// rune is an alias for int32 and is equivalent to int32 in all ways. It is
// used, by convention, to distinguish character values from integer values.
type rune = int32

byte类型本质上是uint8类型的别名,代表的就是ascll码的一个字符

rune类型本质上其实是int32类型的别名,代表的就是一个UTF-8字符

你可能感兴趣的:(golang,java,开发语言,面试,后端)