What does the symbol \0 mean in a string-literal?

后端 未结 6 1904
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 12:26

Consider following code:

char str[] = \"Hello\\0\";

What is the length of str array, and with how much 0s it is ending?

6条回答
  •  醉酒成梦
    2020-11-27 13:07

    Specifically, I want to mention one situation, by which you may confuse.

    What is the difference between "\0" and ""?

    The answer is that "\0" represents in array is {0 0} and "" is {0}.

    Because "\0" is still a string literal and it will also add "\0" at the end of it. And "" is empty but also add "\0".

    Understanding of this will help you understand "\0" deeply.

提交回复
热议问题