Can I copy a string in an empty string?

后端 未结 3 700
温柔的废话
温柔的废话 2021-01-25 13:31

Suppose I do like this to copy the string.

char str[] = \"\";
char *str2 = \"abc\";
strcpy(str, str2);
printf(\"%s\", str);  // \"abc\"
printf(\"%d\", strlen(str         


        
3条回答
  •  一整个雨季
    2021-01-25 13:59

    It actually gives you undefined behavior, but your program doesn't have to fail because of that. That's how undefined behavior works.

提交回复
热议问题