what should strlen() really return in this code?

后端 未结 4 1205
南旧
南旧 2021-01-21 13:34
#include 
#include 
#include 
int main(void)
{
    char qq[] = {\'a\' , \'b\' , \'c\' , \'d\'};
    char qqq[] = \"abcd\";         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-21 14:10

    Your string is not null-terminated. That means your code is not deterministic. strlen() will terminate whenever it encounters a \0 (null byte/character); the result can vary due to it sequential scanning until the \0 is encountered.

提交回复
热议问题