The terminating NULL in an array in C

前端 未结 9 1009
走了就别回头了
走了就别回头了 2021-01-21 04:15

I have a simple question.
Why is it necessary to consider the terminating null in an array of chars (or simply a string) and not in an array of integers. So when i want a

9条回答
  •  囚心锁ツ
    2021-01-21 04:41

    The reason is it was a design choice of the original implementors. A null terminated string gives you a way to pass an array into a function and not pass the size. With an integer array you must always pass the size. Ints convention of the language nothing more you could rewrite every string function in c with out using a null terminator but you would allways have to keep track of your array size.

提交回复
热议问题