Do string literals that end with a null-terminator contain an extra null-terminator?

后端 未结 1 1043
名媛妹妹
名媛妹妹 2020-12-13 17:27

For example:

char a[] = \"abc\\0\";

Does standard C say that another byte of value 0 must be appended even if the string alrea

相关标签:
1条回答
  • 2020-12-13 17:45

    All string literals have an implicit null-terminator, irrespective of the content of the string.

    The standard (6.4.5 String Literals) says:

    A byte or code of value zero is appended to each multibyte character sequence that results from a string literal or literals.

    So, the string literal "abc\0" contains the implicit null-terminator, in addition to the explicit one. So, the array a contains 5 elements.

    0 讨论(0)
提交回复
热议问题