what should strlen() really return in this code?

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


        
4条回答
  •  天命终不由人
    2021-01-21 13:59

    strlen() computes length of string but char qq[] = {'a' , 'b' , 'c' , 'd'}; is not string. Undefined results are obtained when 'Non-String' data is passed to strlen.

    Strings are null terminated in c.

    It should be char qq[] = {'a' , 'b' , 'c' , 'd','\0'};

提交回复
热议问题