Is it wrong to break the c-string with 0 instead of "\ 0"?

C-lines have zero completion, which means that in char -array char in the index strlen()there is a byte with all bits set to 0. I saw code where '\0'an integer is used instead 0. But since sizeof(int) > sizeof(char), it can actually write for the allocated space for the array - am I mistaken? Or does the compiler explicitly discard a intin charin such a situation?

+3
source share
2 answers

Yes, you are mistaken - the zero value will be truncated. After all, if you write:

char c = 0;

, c, . - :

char c = 12345;

. GCC :

c.c:2: warning: overflow in implicit constant conversion

.

+10

0 char s, int char.

'\0' int ( , ), somechararray[x]=0 somechararray[x]='\0' .

'\0', , .

+13

Source: https://habr.com/ru/post/1732658/


All Articles