Not null-terminating a C-style string

后端 未结 6 2073
萌比男神i
萌比男神i 2021-01-24 12:08

Given a string , say ,

char *str = \"Hello,StackOverflow!\"
char newStr[30];
int l = strlen(str);
for(int i =0 ; i

        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-24 12:38

    By chance, most of the time the uninitialized bytes in newStr happen to be 0 in your particular case.

提交回复
热议问题