恋喵大鲤鱼 2019-01-13 21:39 采纳率: 33.3%
浏览 1652
已采纳

go为什么不能获取字符串某个字符地址?

go为什么不能获取字符串某个字符地址?go如此设定的目的是什么?

  • 写回答

2条回答 默认 最新

  • oyljerry 2019-01-14 09:53
    关注

    这个是go的字符串规定的,因为它是immutable类型,所以让你取某个字符的地址,官方不觉得有啥意义

    A string type represents the set of string values. A string value is a (possibly empty) sequence of bytes. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is string.

    The length of a string s (its size in bytes) can be discovered using the built-in function len. The length is a compile-time constant if the string is a constant. A string's bytes can be accessed by integer indices 0 through len(s)-1. It is illegal to take the address of such an element; if s[i] is the i'th byte of a string, &s[i] is invalid.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?