Why do strings in C need to be null terminated?

前端 未结 9 1184
青春惊慌失措
青春惊慌失措 2020-11-29 04:53

Just wondering why this is the case. I\'m eager to know more about low level languages, and I\'m only into the basics of C and this is already confusing me.

Do langu

9条回答
  •  日久生厌
    2020-11-29 05:22

    It is a convention - one could have implemented it with another algorithm (e.g. length at the beginning of the buffer).

    In a "low level" language such as assembler, it is easy to test for "NULL" efficiently: that might have ease the decision to go with NULL terminated strings as opposed of keeping track of a length counter.

提交回复
热议问题