how to make a not null-terminated c string?

前端 未结 7 1093
無奈伤痛
無奈伤痛 2020-12-19 07:18

i am wondering :char *cs = .....;what will happen to strlen() and printf(\"%s\",cs) if cs point to memory block which is huge but with no \'\\0\' in it? i write these lines

7条回答
  •  眼角桃花
    2020-12-19 07:48

    The C standard does not define the term string until the section 7 - Library functions. The definition in C11 7.1.1p1 reads:

    1. A string is a contiguous sequence of characters terminated by and including the first null character.

    (emphasis mine)

    If the definition of string is a sequence of characters terminated by a null character, a sequence of non-null characters not terminated by a null is not a string, period.

提交回复
热议问题