Is it necessary to supply the null character when declaring an character's array?

前端 未结 3 1243
孤城傲影
孤城傲影 2020-12-21 09:22

A string constant in C is stored as a character array, while creating such an array element by element, is it necessary to supply the null character.

I need to store

3条回答
  •  情深已故
    2020-12-21 09:51

    No, but you should leave out number

    char S[]= "hello\n";
    

    will have the trailing 0 character and the array sized as needed.

    With number too small you could accidentally cut off the 0 character.

提交回复
热议问题